Ad

Sending A Request To A Php Web Service From IOS

- 1 answer

I have a question relating to sending a POST request from an iOS app to a web service written in php, that will ultimately query a MySQL database.

tldr: How do I view the contents of the POST variables directly in the browser window, without refreshing?

Long version:

I had written my Swift code in Xcode, with NSURLSession, request, data etc.

I had a php web page set to var_dump($_POST); so that I could check that the data was sent in correctly (my data was a hard-coded string in Xcode for testing purposes).

I couldn't for the life of me figure out why I kept getting empty POST variables, until I decided to add a test query statement to my web page binding the POST variable. Lo and behold, the query ran successfully and my table updated.

I now realise that the reason I thought the POST variable was empty was because I was refreshing the web page in order to see the results of my var_dump. I now also know that this was deleting the POST data, because when I repeated this action with the query statement, my table was getting NULL rows.

My question is how do I view the contents of the POST variables directly in the browser window, without refreshing? I know this must be a real noob goose chase I've led myself on... but I am a noob.

Thank you

Ad

Answer

You would need to modify the service itself to output those values in some way. If this is strictly for debugging, you are better off having the service write out to a log file instead. If this is part of the requesting applications call and the data needs to be displayed to the user, the service should probably return either an XML or JSON string response that your application can parse. Otherwise, you can use Fiddler to monitor your web traffic.

Ad
source: stackoverflow.com
Ad