[HTTP.PUT] Response for preflight is invalid (redirect)

Hi all,

I have this error when I will try this;

 return new Promise((resolve, reject) => {
                this.http.post('http://urlt/api/index2.php/', data, options)
                    .subscribe(result => {
                        debugger;
                    }, (err: Response) => {
                        debugger;
                        console.log(err.json());
                    });

ERROR: Failed to load http://url/api/index2.php/: Response for preflight is invalid (redirect)

It’s when I run ‘ionic serve’. Http.get run correctly

Ain’t that CORS problem? If is there any complex header on your request options, try post it only with application/x-www-form-urlencoded or multipart/form-data or text/plain or no header at all…

1 Like

I tried it, but can’t pass parameters :frowning:

  let urlSearchParams = new URLSearchParams();
       urlSearchParams.append('userId', '2');
       urlSearchParams.append('email', 'p@es.es');
       var headers = new Headers();
       headers.append('Content-Type', 'application/x-www-form-urlencoded');



       this.http.post('http://url/index2.php/user', urlSearchParams, {headers:headers}).subscribe(
             data => {
                 debugger;
               alert('ok');
             },
             error => {
                debugger;
               console.log(JSON.stringify(error.json()));
             }
           )

There’s a couple browser Add-ons/plugins that enable CORS on all req/resp. You can try go back to your old request code and try some of that… But it will work only on your browser, so you got to enable CORS anyway on your API server, don’t know if its yours tho…

https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

I was facing the same problem.

use https instead http in api url