ok, i have been searching the web for hours now and found a lot of results but no working ones
I am developing a app in ionic 4. Up till now i was using my local “api” to test (which works) but now i want to test it with the live version which is build using laravel - it is a exact copy of the local version but then live on the domain.
I have installed https://github.com/barryvdh/laravel-cors to handle the cors and when i test the cors on https://www.test-cors.org it shows:
date: Fri, 07 Jun 2019 22:18:39 GMT
content-encoding: gzip
server: Google Frontend
access-control-allow-origin: *
etag: "1rO4KQ"
allow: POST, GET, OPTIONS, PUT, DELETE
access-control-allow-methods: POST, GET, OPTIONS, PUT, DELETE
content-type: text/html
status: 200
x-cloud-trace-context: c463d031b08229c22feccaba743c28a5
cache-control: public, max-age=600
access-control-allow-headers: access-control-allow-headers,access-control-allow-methods,access-control-allow-origin,content-type
expires: Fri, 07 Jun 2019 22:28:39 GMT
so i guess my server side cors is ok. Now in ionic im doing the following:
getPartnersForZipcode(zipcode: string): Observable<any> {
return this.http.post(this.baseUrl+'/search-partners', {zipcode:zipcode}, this.httpOptions).pipe(
map(results => results),
);
as http options im using
httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Access-Control-Allow-Origin':'*',
'Access-Control-Allow-Methods':'POST, GET, PUT, OPTIONS, DELETE, PATCH',
'Access-Control-Allow-Headers': 'Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With',
})
*I tried it also with no headers, also with only content type etc… none made a difference
which is using the package import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http';
In postman i get a good response with data
but in ionic (using ionic --serve and devapp on device (ios)) im getting CORS error
…i dont know whats happening… why do my requests dont work in ionic?