ionic-team / ionic-team/ionic-cli

Http post not works with new version

未关闭
#2,913 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
TypeScript
星标
2k
派生
682
PR 合并指标
30 天内没有已合并 PR

描述

Hello,

I am pretty desperate, I don’t understand why the http post does not work after updated to newer version.
I test both on IOS device.

Works: The code below is with version @angular/http 4.4.3
`public login(username: string, passwd: string): Observable {`
`let headers = new Headers({'Content-Type': 'application/x-www-form-urlencoded'});`
`let options = new RequestOptions({headers: headers, withCredentials: true });`
`let params: URLSearchParams = new URLSearchParams();`
`params.set('target', 'https://xxx');`
`params.set('username', username);`
`params.set('password', passwd);`
`return this.http.post('https://xxx', params, options)`
`.map(this.returnData)`
`.catch(this.handleError);`
}`

`private returnData(res: Response) {`
`if (JSON.stringify(res.text()).indexOf('error') === -1) {`
`return res || {};`
`} else {`
`throw {message: 'Error occured'};`
`}`
`}`

`private handleError (error: any) {`
`return Observable.throw(error.message);`
`}`

Not works: The code below is with newer version @angular/http 5.1.0

`public login(username: string, passwd: string): Observable {`
` const headers = new HttpHeaders();`
` headers.append('Content-Type,', 'application/x-www-form-urlencoded');`
` const options = {headers: headers, withCredentials: true};`
` const body = {`
` target: 'https://xxx',`
` username: username,`
` password: passwd`
`};`
` return this.http.post('https://xxx', body, options)`
` .map(this.returnData)`
` .catch(this.handleError);`
`}`

` private returnData(res: HttpResponse) {`
` if (res.ok) {`
` return res || {};`
` } else {`
` throw {message: 'Error occured'};`
` }`
` }`

` private handleError(error: HttpErrorResponse) {`
` return Observable.throw(error.message);`
` }`

贡献指南

打开贡献指南

调研方向

Start with the login method and compare the @angular/http 4.4.3 request against the Angular 5.1.0 request shown in the issue. Reproduce the POST on an iOS device, then determine what changed in the request or response handling and verify the behavior with a working request.

由索引模型根据 Issue 内容生成。

评估

技术栈
angular, typescript
领域
api, frontend
Issue 类型
缺陷
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
需要澄清
新手友好度
15/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。