Question : iPhone - Web service client app

Hi

I am writing an app that’s a very simple web service client.
I have the following questions:
1. Is there a standard common way to write the web service consumption part so that it won’t interfere with the main GUI thread?  Is it common practice to use the main thread considering the web request should take a very short time to complete (but never know)?
Any links to tutorials?
2. All examples I saw call the web service via GET. I need to POST the data to the web service.
Any known samples/tutorials that use POST?

Answer : iPhone - Web service client app

asuming that you're using NSURLRequest and NSURLConnection and friends, and you should simply stick to the delegation-paradigm and implement the appropreate delegate-methods, there's no need to bother with threading or (a)synchronous-issues.
connections are attached to the runloop, and will notify the delegate whenever something interesting happens. they are running on the main thread, but won't block.

About using POST instead of GET - there's not much to it.
Below a super simple setup, where is asumed that myDelegate, self.url, indata have already been assigned the appropreate values..
(not tested, cut/pasted as is..)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:

NSMutableURLRequest * request = [NSMutableURLRequest
				requestWithURL:self.url
				cachePolicy:NSURLCacheStorageNotAllowed
				timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:indata];


NSURLConnection * connection = [NSURLConnection connectionWithRequest:request
							     delegate:mdelegate];
Random Solutions  
 
programming4us programming4us