哪个 NSURLConnection 包装器同样能很好地处理 GET 和 POST?
哪个 NSURLConnection 包装器同样能很好地处理 GET 和 POST ?
对于 GET 方法,我更喜欢 Google 的 GTMHTTPFetcher 而不是 ASIHTTPRequest。 ASIHTTPRequest 使用委托,这可能是您通常会想到的想法。但这正是我选择不使用它的原因,因为当您有多个连接(在我的情况下有很多连接)时,每个连接都有自己的委托,最终会得到太多的对象。或者您可以只有 1 个委托,但您已经找到一种方法来找出哪个响应针对哪个连接。
在我看来,GTMHTTPFetcher 处理这种方式要好得多。它对 1 个连接使用 1 个 SEL,有点像目标操作模型。代码比委托模型干净得多。
但是对于POST方法,ASIHTTPRequest有ASIFormDataRequest。我没有找到使用 GTMHTTPFetcher 进行 POST 的简单方法。它确实有 setPostData 方法来设置发布数据。但是你必须自己设置帖子正文和那些哑剧参数(据我所知)这就是令人头痛的地方。我发现它还有另一个名为GTMHTTPUploadFetcher的类。但我真的不知道如何使用它(我不断收到 NSAssert“需要上传位置 hdr”)。
所以对于 POST,我想 ASIHTTPRequest 更容易。
我没有机会使用 facebook-ios-sdk 。并想听听对此的其他意见。
那么 NSURLConnection 包装器是否可以很好地处理 GET 和 POST 呢?知道如何使用 GTMHTTPUploadFetcher 吗?
Which NSURLConnection wrapper handles GET and POST equally well ?
For GET method, I prefer google's GTMHTTPFetcher over ASIHTTPRequest. ASIHTTPRequest uses delegate, which probably the idea you will come up with normally. But that's the exactly reason I chose not to use it because when you have several connections(many connections in my case), then each connection has its own delegate and you end up with too many object. Or you can have just 1 delegate but you have find a way to find out which response is for which connection.
GTMHTTPFetcher handle this way much better in my opinion. It uses 1 SEL for 1 connection, sorta like target-action model. The code is much cleaner than delegate model.
But for POST method, ASIHTTPRequest has ASIFormDataRequest. I did not find an easy way to do POST with GTMHTTPFetcher. It does have setPostData method to set post data. But you have to set post body and those mime parameters by yourselves(from what I have see) And that's the headache. I find it has another class called GTMHTTPUploadFetcher. But I can't really figure out how to use it (I keep getting the NSAssert "need upload location hdr").
So for POST, I guess ASIHTTPRequest is easier.
I did not get a chance to use facebook-ios-sdk. And would like to hear other opinion about it.
So is there NSURLConnection wrapper handle both GET and POST well ? And any idea how to use GTMHTTPUploadFetcher?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 GTMMIMEDocument 类创建一个通过 GTMHTTPFetcher(或通过任何其他需要 NSInputStream 的东西)上传的流。一个例子是 此处。
GTMMIMEDocument 保留要上传的数据部分的稀疏列表,避免在内存中重复数据。
The GTMMIMEDocument class is used to create a stream for uploading via GTMHTTPFetcher (or via anything else that takes an NSInputStream.) An example is here.
GTMMIMEDocument keeps a sparse list of the data parts to be uploaded, avoiding duplicating the data in memory.