How to send a HTTP request to a web service using Objective-C ? I need to fetch some data from my MySQL DB, so I need to send the request so I could fetch the data.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Edit, because this is a popular question and time keeps going on.
In the meantime Apple introduced NSJSONSerialization. Have a look a the docs: https://developer.apple.com/documentation/foundation/jsonserialization
Only if you need to create code for iOS earlier than 5.0 you may want to use the json-framwork as mentioned below.
Besides that, the following original answer is still valid:
Assuming that you exchange your data in JSON, you may be interested in reading this.
http://iosdevelopertips.com/cocoa/json-framework-for-iphone-part-2.html
However, the first part of that article answers your more general question on how to receive data from a web server/service:
This is a simple example of a http request and surely good enough for your next steps.
This method is given a URL and it returns the data sent by the server in an NSString.
Once that is working properly you will like to avoid that your app freezes while the request is “on the air”.
You can fix that by asynchronous requests. Google or the search on stackoverflow will provide you with links to examples and tutorials about that. But I suggest to go from here first, although this may not be the final solution.