I am building an app using ionic, WP rest api and everything worked fine.
I am using http post, get, put and they all work fine with WP rest api. I installed Push Notifications for Wordpress Lite plugin which I a managed to setup and actually receive a notification but when I try to receive or send data to plugin with http post and get methods I receive No ‘Access-Control-Allow-Origin’ header is present on the requested resource error. This is the example from plugin documentation - GET /pnfw/posts/?token=device_id&os=iOS
It is really strange that WP rest api works and the plugin doesn’t since they are both on the same domain.
I have no idea what should I do to fix this so I hope someone here has an idea what might be causing this.
on the http request add a Access-Control-Allow-Origin header in the request options.
google what that header should look like
I tried something like this but didn’t help me:
let headers = new HttpHeaders();
headers.append('Access-Control-Allow-Origin' , '*');
headers.append('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT');
headers.append('Accept','application/json');
headers.append('content-type','application/x-www-form-urlencoded');
this.http.post('http://www.eventfingere.com/pnfw/posts/?', dataSend , {headers: headers}).subscribe(sent => {
console.log(JSON.stringify(sent))
}, err => {
console.log(JSON.stringify(err))
});
just
dataSend , headers)
headers is a structure already
It seems that I am able to get with http.get method and the plugin api receives the data but I continue to receive the same error from console.log so I am unable to read the data that I should receive on success
But when I try to post with http.post in the plugin debug I receive this error:
/pnfw/posts/? API Error (500) from IP address 185.150.233.50: Internal Server Error, Mandatory parameter os missing.
I copied the dataSend and made the same request in Postman and from there it works normally