POST request in Ionic2

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

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});,data,options)
    .map(res =>res.json())
    .subscribe(data =>{

The error I’m getting on console is:image

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.

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 :slight_smile:

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

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

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

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

It’s expecting a POST request

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

Sure, will try it out

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

POST /searcharticle2 HTTP/1.1
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

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

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

AFAIK, iOS mandates https URLs.