# How to solve this error angular http

**URL:** <https://forum.ionicframework.com/t/how-to-solve-this-error-angular-http/114028>\
**Category:** ionic-v3\
**Created:** [December 1, 2017, 7:56am UTC](https://forum.ionicframework.com/t/how-to-solve-this-error-angular-http/114028 "2017-12-01T07:56:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nagarajsabhahith](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/nagarajsabhahith/32/133450_2.png) [@nagarajsabhahith](https://forum.ionicframework.com/u/nagarajsabhahith)\
**Post date:** [December 1, 2017, 7:56am UTC](https://forum.ionicframework.com/t/how-to-solve-this-error-angular-http/114028/1 "2017-12-01T07:56:00Z")

</div>

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

 ![error](https://global.discourse-cdn.com/ionicframework/original/3X/e/2/e2568a2ffecf9686d3fae6b96ee19c282f3af762.png)

but i am getting response in postman

---

<div class="post-metadata">

**Author:** ![nagarajsabhahith](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/nagarajsabhahith/32/133450_2.png) [@nagarajsabhahith](https://forum.ionicframework.com/u/nagarajsabhahith)\
**Post date:** [December 1, 2017, 9:14am UTC](https://forum.ionicframework.com/t/how-to-solve-this-error-angular-http/114028/2 "2017-12-01T09:14:24Z")

</div>

Guys please help me out

---

<div class="post-metadata">

**Author:** ![wthijmen](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/wthijmen/32/113686_2.png) [@wthijmen](https://forum.ionicframework.com/u/wthijmen)\
**Post date:** [December 1, 2017, 9:15am UTC](https://forum.ionicframework.com/t/how-to-solve-this-error-angular-http/114028/3 "2017-12-01T09:15:48Z")

</div>

> [@nagarajsabhahith](#):
>
> Guys please help me out

Read this forum post, about facing the same problem (Unauthorized).

> [@401 (Unauthorized) \[SOLVED\]](https://forum.ionicframework.com/t/401-unauthorized-solved/87929):
>
> 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 …

---

<div class="post-metadata">

**Author:** ![nagarajsabhahith](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/nagarajsabhahith/32/133450_2.png) [@nagarajsabhahith](https://forum.ionicframework.com/u/nagarajsabhahith)\
**Post date:** [December 2, 2017, 10:10am UTC](https://forum.ionicframework.com/t/how-to-solve-this-error-angular-http/114028/4 "2017-12-02T10:10:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Thavarajan](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/thavarajan/32/103608_2.png) [@Thavarajan](https://forum.ionicframework.com/u/Thavarajan)\
**Post date:** [December 2, 2017, 11:05am UTC](https://forum.ionicframework.com/t/how-to-solve-this-error-angular-http/114028/5 "2017-12-02T11:05:14Z")

</div>

did you notice the double slash before get categories

---

<div class="post-metadata">

**Author:** ![nagarajsabhahith](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/nagarajsabhahith/32/133450_2.png) [@nagarajsabhahith](https://forum.ionicframework.com/u/nagarajsabhahith)\
**Post date:** [December 2, 2017, 4:06pm UTC](https://forum.ionicframework.com/t/how-to-solve-this-error-angular-http/114028/6 "2017-12-02T16:06:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nagarajsabhahith](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/nagarajsabhahith/32/133450_2.png) [@nagarajsabhahith](https://forum.ionicframework.com/u/nagarajsabhahith)\
**Post date:** [December 2, 2017, 4:42pm UTC](https://forum.ionicframework.com/t/how-to-solve-this-error-angular-http/114028/7 "2017-12-02T16:42:12Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 10:01pm UTC](https://forum.ionicframework.com/t/how-to-solve-this-error-angular-http/114028/8 "2021-07-19T22:01:11Z")

</div>

Closed on July 19, 2021, 10:01pm UTC


