Reputation: 447
I want to do a HTTP post, updating some information to the server
The URL might be "http://www.aaa.com/aaa.aspx?name=John&pw=123&age=25"
And I think this method should work:
NSURL* url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSData* returnData = [NSData initWithContentsOfURL: url];
[NSString* strRet = [[NSString alloc] initWithData:data encoding:NSUTF8String];
So how could know the update is sucessful? What would be in the NSData returned?
@"200" or some other string returned by the server, such as @"YES"?
Thanks
Upvotes: 0
Views: 1777
Reputation: 11148
You could use
NSError *error = nil;
NSString *str = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error];
and have a look into error
to check if the request was successfully.
For bigger requests, please check this link: Objective-C: server requests in a thread (like AsyncTask in Android)
Upvotes: 1
Reputation: 19333
I think your request would end up being a GET request. And the data returned would be whatever data the web site returns for that URL, not the http headers. I recommend using the excellent ASIHTTPRequest library: http://allseeing-i.com/ASIHTTPRequest/ for communicating with web sites, determining POST/GET mode, etc.
Upvotes: 1