I'm new to objective-c, and I'm starting to put a lot of effort into the request / response at a recent stage. I have a working example that can call a url (via http GET) and parse the returned json.
A working example of this is below.
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { [responseData setLength:0]; } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { [responseData appendData:data]; } - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { NSLog([NSString stringWithFormat:@"Connection failed: %@", [error description]]); } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { [connection release];
My first question is: will this approach expand? Or this is not async (this means that I am blocking the user interface thread while the application is waiting for a response)
My second question is: how can I change the request part of this to do POST instead of GET? Is it easy to change HttpMethod like that?
[request setHTTPMethod:@"POST"];
And finally, how to add a json dataset to this post as a simple string (for example)
{ "magic":{ "real":true }, "options":{ "happy":true, "joy":true, "joy2":true }, "key":"123" }
Thank you in advance
json objective-c iphone cocoa-touch nsurlrequest
Toran Billups Dec 16 '10 at 2:30 2010-12-16 02:30
source share