开发者

iOS HTTP Communication setup

So I am making an app that is supposed to communicate with a webservice via basic HTTP requests. I spent quite a lot of time yesterday looking online and through the developer documentation not finding a whole lot of useful stuff. The best I managed to find was the CFNetwork Programming Guide in the iPhone developer docs, but this seemed to be lacking a lot of information and was very confusing.

For example: It tells me how to create开发者_如何学JAVA requests and responses, deserialize both, but not how to submit requests, or receive responses. And as for a confusing bit, when creating the response it wants me to provide the status code. Shouldn't the response already contain that information?

Can someone please help? I really need to get this done soon.


If you simply want to be able to fire HTTP requests off, then I'd have thought using something like the NSString stringWithContentsOfURL:encoding:error: and writeToURL:atomically:encoding:error: methods would be a good starting point.

Alternatively, if you want to be able to fire off requests asynchronously, the NSURLConnection class should prove ideal.


While iOS native networking support is good, it is much easier to use this library: http://allseeing-i.com/ASIHTTPRequest/How-to-use It has several advantages, good documented examples and used by many projects.


We did a bit of a walk through on our blog: How to consume JSON or XML Web APIs on iPhone smoothly It uses the ASIHTTPRequest library which makes things a lot easier.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜