Objective-C / iPhone的好HTTP库?

时间:2022-09-07 09:20:04

UPDATE: this question is obviously obsolete (see the date). I recommend just using modern iOS7 features like NSURLSession. The question is preserved for historical accuracy, I guess.

更新:这个问题显然已经过时(见日期)。我建议只使用像NSURLSession这样的现代iOS7功能。我猜这个问题保留了历史的准确性。

What's a good HTTP library for (desktop Cocoa and) iPhone? Should just have a good interface to the basics like HTTP headers, get/post values (request string creation, URL encoding/decoding), sync and async requests... preferably pure Obj-C implementation. NSURL* is somewhat lacking.

什么是(桌面Cocoa和)iPhone的优秀HTTP库?应该只有一个很好的接口,如HTTP标头,获取/发布值(请求字符串创建,URL编码/解码),同步和异步请求......最好是纯粹的Obj-C实现。 NSURL *有点缺乏。

5 个解决方案

#1


12  

Check out All Seeing Interactives ASIHTTPRequest library

查看All Seeing Interactives ASIHTTPRequest库

#2


3  

How about what's already built into Cocoa in the forms of NSURLRequest and it's subclass NSMutableURLRequest? You'll probably also get to use NSURLConnection along with it...

如何以NSURLRequest的形式构建到Cocoa中,它的子类是NSMutableURLRequest?您可能也会使用NSURLConnection ......

#3


1  

I've had great success with the Three20 Project's TTURLRequest. It's a genericized version of the UI Elements used in the Facebook App.

我在Three20项目的TTURLRequest上取得了巨大的成功。它是Facebook应用程序中使用的UI元素的通用版本。

#4


1  

Setting the post parameters in the HTTP body is pretty straight forward with NSMutableURLRequest, you can wrap it in a convenience method via a category if that's more desirable, similar to the OAuth library on google code:

使用NSMutableURLRequest在HTTP正文中设置post参数是非常简单的,如果需要的话,可以通过类别将其包装在一个便利方法中,类似于Google代码上的OAuth库:

http://oauth.googlecode.com/svn/code/obj-c1/OAuthConsumer/NSMutableURLRequest+Parameters.m

Checkout the setParameters override, specifically these lines:

检查setParameters覆盖,特别是这些行:


NSData *postData = [encodedParameterPairs dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
        [self setHTTPBody:postData];
        [self setValue:[NSString stringWithFormat:@"%d", [postData length]] forHTTPHeaderField:@"Content-Length"];
        [self setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];

Of course, you'll want to adjust the content-type header for the specific content of your post body (e.g. json, xml, etc).

当然,您需要调整帖子主体特定内容的内容类型标题(例如json,xml等)。

#5


0  

Check out this http://code.tutsplus.com/tutorials/ios-quick-tip-interacting-with-web-services--mobile-10278 there is 3 libs. you can use...i think AFNetworking is good.

看看这个http://code.tutsplus.com/tutorials/ios-quick-tip-interacting-with-web-services--mobile-10278有3个库。你可以使用...我认为AFNetworking很好。

#1


12  

Check out All Seeing Interactives ASIHTTPRequest library

查看All Seeing Interactives ASIHTTPRequest库

#2


3  

How about what's already built into Cocoa in the forms of NSURLRequest and it's subclass NSMutableURLRequest? You'll probably also get to use NSURLConnection along with it...

如何以NSURLRequest的形式构建到Cocoa中,它的子类是NSMutableURLRequest?您可能也会使用NSURLConnection ......

#3


1  

I've had great success with the Three20 Project's TTURLRequest. It's a genericized version of the UI Elements used in the Facebook App.

我在Three20项目的TTURLRequest上取得了巨大的成功。它是Facebook应用程序中使用的UI元素的通用版本。

#4


1  

Setting the post parameters in the HTTP body is pretty straight forward with NSMutableURLRequest, you can wrap it in a convenience method via a category if that's more desirable, similar to the OAuth library on google code:

使用NSMutableURLRequest在HTTP正文中设置post参数是非常简单的,如果需要的话,可以通过类别将其包装在一个便利方法中,类似于Google代码上的OAuth库:

http://oauth.googlecode.com/svn/code/obj-c1/OAuthConsumer/NSMutableURLRequest+Parameters.m

Checkout the setParameters override, specifically these lines:

检查setParameters覆盖,特别是这些行:


NSData *postData = [encodedParameterPairs dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
        [self setHTTPBody:postData];
        [self setValue:[NSString stringWithFormat:@"%d", [postData length]] forHTTPHeaderField:@"Content-Length"];
        [self setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];

Of course, you'll want to adjust the content-type header for the specific content of your post body (e.g. json, xml, etc).

当然,您需要调整帖子主体特定内容的内容类型标题(例如json,xml等)。

#5


0  

Check out this http://code.tutsplus.com/tutorials/ios-quick-tip-interacting-with-web-services--mobile-10278 there is 3 libs. you can use...i think AFNetworking is good.

看看这个http://code.tutsplus.com/tutorials/ios-quick-tip-interacting-with-web-services--mobile-10278有3个库。你可以使用...我认为AFNetworking很好。