ios - How to write data to the web server from iphone application? -


i looking forward posting data , information on web server through iphone application. need in doing so. not getting way post data web server iphone sdk.

it depends in way want send data web server. if want use http post method, there (at least) 2 options. can use synchronous or asynchronous nsurlrequest. if want post data , not need wait response server, recommend asynchronous one, because not block user interface. i.e. runs "in background" , user can go on using (that interacting with) app. asynchronous requests use delegation tell app request sent, cancelled, completed, etc. can response via delegate methods if needed.

here example asynchronous http post request:

// define form fields here: nsstring *content = @"field1=42&field2=hello";  nsmutableurlrequest *request = [[nsmutableurlrequest alloc] initwithurl:[nsurl urlwithstring:@"http://www.example.com/form.php"]]; [urlrequest sethttpmethod:@"post"]; [urlrequest sethttpbody:[content datausingencoding:nsisolatin1stringencoding]];  // generates autoreleased nsurlconnection [nsurlconnection connectionwithrequest:request delegate:self]; 

please refer nsurlconnection class reference details on delegate methods.

you can send synchronous request after generating request:

[nsurlconnection sendsynchronousrequest:request returningresponse:nil error:nil]; 

if pass nsurlresponse ** returning response, find server's response in object pointer points to. keep in mind ui block while synchronous request processed.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -