ionic-team / ionic-team/ionic-cli

Http post not works with new version

Aperta
#2,913 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
TypeScript
Stelle
2k
Fork
682
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.