ionic-team / ionic-team/ionic-cli
Http post not works with new version
- Langage dominant
- TypeScript
- Étoiles
- 2k
- Forks
- 682
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
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);`
` }`
Guide de contribution
Ouvrir le guide de contribution
Évaluation
Cette issue n'a pas encore été évaluée.