# POST request in Ionic2

**URL:** <https://forum.ionicframework.com/t/post-request-in-ionic2/89838>\
**Category:** ionic-v3\
**Created:** [May 11, 2017, 1:48pm UTC](https://forum.ionicframework.com/t/post-request-in-ionic2/89838 "2017-05-11T13:48:13Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![nik2nik](https://avatars.discourse-cdn.com/v4/letter/n/c6cbf5/32.png) [@nik2nik](https://forum.ionicframework.com/u/nik2nik)\
**Post date:** [May 11, 2017, 1:48pm UTC](https://forum.ionicframework.com/t/post-request-in-ionic2/89838/1 "2017-05-11T13:48:13Z")

</div>

I’m sending a post request to the web service but getting the error “forbidden”. Below is my code

```auto
getSearchResults1(term: string){
    let data= JSON.stringify({searchString:term});
    let headers=new Headers({'Content-Type':'application/x-www-form-urlencoded'})
    let options = new RequestOptions({headers:headers});
    this.http.post(myUrl,data,options)
    .map(res =>res.json())
    .subscribe(data =>{
      console.log(data);
    });
    
  }

```

The error I’m getting on console is: ![image](https://global.discourse-cdn.com/ionicframework/original/3X/0/8/08fd18e1792e558f99c5a18802360c77494e1cc6.png)

But when I’m manually entering the url with post data appended to it like: myUrl?searchString=Trump, I get the response from web service. I can’t get to the root of the issue.

---

<div class="post-metadata">

**Author:** ![mich356c](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mich356c/32/105794_2.png) [@mich356c](https://forum.ionicframework.com/u/mich356c)\
**Post date:** [May 11, 2017, 2:26pm UTC](https://forum.ionicframework.com/t/post-request-in-ionic2/89838/2 "2017-05-11T14:26:05Z")

</div>

When you manually write in the data in the URL in your browser it’s a `GET` request, are you expecting a `GET` or a `POST` request in your backend? You should try out Postman to test this kind of stuff really easily 🙂

---

<div class="post-metadata">

**Author:** ![nik2nik](https://avatars.discourse-cdn.com/v4/letter/n/c6cbf5/32.png) [@nik2nik](https://forum.ionicframework.com/u/nik2nik)\
**Post date:** [May 11, 2017, 2:45pm UTC](https://forum.ionicframework.com/t/post-request-in-ionic2/89838/3 "2017-05-11T14:45:36Z")

</div>

The app is already made in native IOS. I checked its code and there its a post request

---

<div class="post-metadata">

**Author:** ![rafpe](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rafpe/32/109353_2.png) [@rafpe](https://forum.ionicframework.com/u/rafpe)\
**Post date:** [May 11, 2017, 2:53pm UTC](https://forum.ionicframework.com/t/post-request-in-ionic2/89838/4 "2017-05-11T14:53:25Z")

</div>

Is there any chance you have IP restriction on your backend ? Forbidden is kinda self explanatory

---

<div class="post-metadata">

**Author:** ![mich356c](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mich356c/32/105794_2.png) [@mich356c](https://forum.ionicframework.com/u/mich356c)\
**Post date:** [May 11, 2017, 3:02pm UTC](https://forum.ionicframework.com/t/post-request-in-ionic2/89838/5 "2017-05-11T15:02:54Z")

</div>

What I mean though is, what request is the backend expecting? A `GET` or a `POST`?

---

<div class="post-metadata">

**Author:** ![nik2nik](https://avatars.discourse-cdn.com/v4/letter/n/c6cbf5/32.png) [@nik2nik](https://forum.ionicframework.com/u/nik2nik)\
**Post date:** [May 11, 2017, 3:16pm UTC](https://forum.ionicframework.com/t/post-request-in-ionic2/89838/6 "2017-05-11T15:16:05Z")

</div>

Nope. If that had been the case then we would have been informed

---

<div class="post-metadata">

**Author:** ![nik2nik](https://avatars.discourse-cdn.com/v4/letter/n/c6cbf5/32.png) [@nik2nik](https://forum.ionicframework.com/u/nik2nik)\
**Post date:** [May 11, 2017, 3:16pm UTC](https://forum.ionicframework.com/t/post-request-in-ionic2/89838/7 "2017-05-11T15:16:28Z")

</div>

It’s expecting a POST request

---

<div class="post-metadata">

**Author:** ![mich356c](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mich356c/32/105794_2.png) [@mich356c](https://forum.ionicframework.com/u/mich356c)\
**Post date:** [May 11, 2017, 3:30pm UTC](https://forum.ionicframework.com/t/post-request-in-ionic2/89838/8 "2017-05-11T15:30:37Z")

</div>

Try recreating the exact same POST request in Postman, does it work there? Maybe there is some odd CORS handling API wise

---

<div class="post-metadata">

**Author:** ![nik2nik](https://avatars.discourse-cdn.com/v4/letter/n/c6cbf5/32.png) [@nik2nik](https://forum.ionicframework.com/u/nik2nik)\
**Post date:** [May 11, 2017, 4:06pm UTC](https://forum.ionicframework.com/t/post-request-in-ionic2/89838/9 "2017-05-11T16:06:16Z")

</div>

Sure, will try it out

---

<div class="post-metadata">

**Author:** ![rafpe](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rafpe/32/109353_2.png) [@rafpe](https://forum.ionicframework.com/u/rafpe)\
**Post date:** [May 11, 2017, 6:43pm UTC](https://forum.ionicframework.com/t/post-request-in-ionic2/89838/10 "2017-05-11T18:43:01Z")

</div>

If I throw single post on that URL I get proper response

```auto
POST /searcharticle2 HTTP/1.1
Host: regulatorynavsvc-dev.pwc.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3087.0 Safari/537.36
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
Cache-Control: no-cache

```

And response is

```auto
{"nodes":[{"node":{"responseCode":"E404","errorMessage":"No records"}}]}

```

So this seems to be working. Maybe you are just sending something the server does not like.

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [May 12, 2017, 2:54am UTC](https://forum.ionicframework.com/t/post-request-in-ionic2/89838/11 "2017-05-12T02:54:15Z")

</div>

AFAIK, iOS mandates `https` URLs.
