I am having an issue related to this new Http.Post of Ionic 3 and Angular 5. Got this issue on ipad App and I didn’t tried on browser.
I end up posting here after trying 7-8 hours.
My controller code:
this.api.post('index.php',
{'data': JSON.stringify(this.pendingRecords)}, {})
.subscribe( response => { console.log(response) };
My API Service code:
post(endpoint: string, body: any, reqOpts?: any) {
let headers = new HttpHeaders();
return this.http.post(this.url + '/' + endpoint, body,
{headers: headers.append('Content-Type', 'application/x-www-form-urlencoded')})
}
My Service headers:
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { map, catchError } from 'rxjs/operators';
If there is any syntax mistakes, please ignore those and provide me any solution(this is code of several modified & trailed attempt).
My back end service is PHP. and it is working fine. I tested my backend service with hardcoded values. it is returning fine. Other wise Post is not at all taking any data. but, some how this Angular/common/http is not taking data to server.
I tried with JQuery sample code of $.POST, with browser extension to bypass CORS. even that is working fine in browser. Finally i don’t how to look at the requests in xcode like chrome network tab, to give you guys more information.
Update: I installed Charles and debugged this ionic app into ipad pro 9’ simulator to check what request is going. here is the result. Even though we are adding headers: application/x-www-urlencoded. it is somehow changing to application/json. is that any way reason because it is not sending data to php file