开发者

objective c http query

Hey, Iam new to objective c and really dont know much about it. I have been given a query that is gonna I need to send data in to the server.Query is like this http://abc.com/insertipademail.php?name=name&email=email I need to enter the name and email I have constructed the string But I dont know how to s开发者_如何学Cend it to the server. Can someone help me out please. Or point me in the right direction. Thanks


For starters, take a look a NSString's stringWithContentsOfURL:encoding:error: method. You could do something like:

// NSString * myURLString = whatever you do to build the url
NSURL * myURL =  [NSURL URLWithString: myURLString];
NSString * response = [NSString stringWithContentsOfURL: myURL encoding: NSUTF8StringEncoding error: NULL];
NSLog(@"The response was: %@", response);

As written, this will ignore all errors and perform the request synchronously. In a real app, you probably want to handle any error that occur, and perhaps perform the request in the background. See the URL Loading System Programming Guide for further documentation. You can also try using any of several open source libraries such as those suggested in David M.'s answer.


I like the library ASIHTTPRequest. There is also HTTPRiot.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜