ionic-team / ionic-team/ionic-cli

Http post not works with new version

Abierto
#2,913 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
TypeScript
Estrellas
2k
Forks
682
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.