Http POST body not received on the server side in ios simulator


#1

Hello,

I have a simple app which makes some requests to a server. With the following code:

let postOptions = {"param1": "1", "param2": "2"}
this.http.post("http://localhost/myurl.php", postOptions).map(res => res.json()).subscribe(data => {
        console.log(data);
}, err => {
        console.log(err);
});

The above request works perfectly on the browser in my local device. I build it for iOS, install it to the simulator from Xcode and when I make the same request, server side does not receive any post body.

I had assumed that it was a problem with my backend tried with something completely different and still post body was not received. I have opened the console from the Safari develop, and inspected the network requests, I see on the inspector that post options are sent to the server, method is POST too as expected but server side does not receive the post body.

There was no such problem until I upgrade from 2.0.0-rc1 to 2.0.0 (updated angular libraries to 2.2.1 from 2.0.0 as well).


#2

Just to make sure… If the phone is also calling localhost, then that’s why. Have you replaced it with your IP, before building it on the phone?

Otherwise, are you absolutely certain that the server is receiving the request at all?


#3

Yes, it’s not a problem with the localhost thing. That part is working fine. I have created a new ionic 2 project from scratch and tried the same code there and it worked. It seems there is a problem with the upgrade from rc.


#4

hi
can you help me.?


#5

Hi, I’d recommend starting your own post, so everything is easier to keep track of! :slight_smile:

@radalin Hmm yeah it was quite an update you made, I’m not sure what it could be, you’d just have to debug your way out of it. The code you provided is the same as I do, so it’s gotta be something else.

And I just realized, are you two working on the same? Considering your names start with the same. If so, just stick to this thread @radid.


#6

nope we are not.

Yeah, I guess I will need to copy paste from the existing app to the app from the scratch.


#7

no hhh i just use this forum for the first time
so i should have create an application and i need someone to help me.


#8

Check out the Getting Started page on the main site, or search for some tutorials on Youtube/Google. If you have any issues please start your own thread!


#9

I’m 95% certain it wasn’t an Ionic update; it was a change Apple made requiring TLS. Can you try using https instead of http?


#10

That’s what I had thought at first, but I guess then normal get requests would not have worked. But I will give it a try and let you know (and it was working before the update and also it’s working with an app from scratch).


#11

OK so I have created a new project from scratch, copied/pasted my code from the old project and it started working. I suppose it was something related to the config.xml or so. Even though I have nearly converted the config files to be identical to each other, it did not worked.