ionic-team / ionic-team/ionic-cli

Http post not works with new version

Đang mở
#2,913 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
TypeScript
Star
2k
Fork
682
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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);`
` }`

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.