Response for preflight has invalid HTTP status code 401
I have started with super app from ionic and i have changed example url to my url
My code is
post(endpoint: string, body: any, reqOpts?: any) {
reqOpts = {
headers: new HttpHeaders().set(‘Authorization’,‘Basic V2FwcHlVSTp3QVBQWXVpQE5T’)
};
return this.http.post(this.url + ‘/’ + endpoint, body, reqOpts);
}
and my error is
but i am getting response in postman
nagarajsabhahith:
Guys please help me out
Read this forum post, about facing the same problem (Unauthorized).
Hi, friends!
When consuming the service it displays the following error:
http://localhost:8080/Api/webresources/v1/usuario/mguillen. Response for preflight has invalid HTTP status code 401 (Unauthorized)
ApiRest.ts
import { Injectable } from '@angular/core';
import { Http, Headers, RequestOptions } from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class ApiRest {
constructor(public http: Http) {
}
public getUsuarioInventiva(usuario: string) {
let …
I have tried a lot of code changes with different different angular versions, unfortunately still i am not able to solve this issue…
My request is send as OPTIONS instead of POST when i will add Authorization in headers
if i remove all the headers then request is on POST
with this Http, Headers, RequestOptions its working in @angular / 2.2.1
but i am not able to solve this in angular 4.4.6 and 5.0.5
did you notice the double slash before get categories
ya i have noticed that and corrected but issue is still same…
I have removed Authorization in my server and tested without headers in http.post, response is coming
but when i will add Authorization, that time request method will automatically changing from POST to OPTIONS
I have added android platform and build apk… i got the response in real device but i didn’t get response in browser with headers…