前段时间用到ASIHTTPRequest做请求时,发现一个问题,相信很多朋友会遇到:使用ASIHTTPRequest请求时,发送了2次(即重复发送了1次),我当时用的是GET方式,在Header里面放些东西。
后来网上找到答案,之前一直没时间写,今天有空,立马给写下。这时stackoverflow上分享的一段话(地址:http://stackoverflow.com/questions/8317662/asihttprequest-request-sent-twice):
This has bitten me too. I was using a GET request to validate a multi-use voucher code on a server. When we added a rate limitation for redeeming codes some customers reported hitting the limit before they should have. Turns out that some of the validations triggered two redeems.
Your request is using the GET method.
The default behavior when using GET is to allow persistent connections (the Keep-Alive HTTP header).
When using a persistent connection your GET request might get retransmitted if something on the network looks wonky (that's a technical term) instead of the request just failing. This is usually desirable because GET requests often do not have any side effects on the server.
POST or PUT requests on the other hand default to not use a persistent connection and will not retransmit your operation, which could well be a credit card purchase or something else with significant side effects.
If you wish to prevent your ASIHTTPRequest GET sometimes sending 2 or more server requests (due to network issues outside your control) you can simply set this flag:
request.shouldAttemptPersistentConnection = NO;
This should take care of the spurious GET duplicates on the server.
解决办法就是request.shouldAttemptPersistentConnection = NO;
分享到:
相关推荐
iOS ASIHttpRequest 请求https
ASIHTTPRequest调用WebService,并进行封装
在网络访问时,一般都建议用异步访问,但是异步访问的话,需要传入delegate,并处理回调。不利于将所有的网络访问的方法集中到一个类中,所以我采用同步访问的方式。后来产品部们要求网络访问可以取消,但是ASIHTTP ...
ASIHTTPRequest网络请求集合,直接引入到项目中使用。
ASIHttpRequest是iOS开发必备的网络数据请求包,使用方便,唯一的缺点是非ARC的,需要设置项目中的非ARC类
使用iOS SDK中的HTTP网络请求API,ASIHTTPRequest就是一个对CFNetwork API进行了封装,并且使用起来非常简单的一套API,
全称是ASIHTTPRequest,外号“HTTP终结者”,可以实现http网络请求,功能十分强大。
ASIHTTPRequest,用于获取下载及其相关处理与应用的功能函数
ASIHTTPRequest使用介绍
使用 iOS SDK 中的 HTTP 网络请求 API,相当的复杂,调用很繁琐,ASIHTTPRequest 就是一个对 CFNetwork API 进行了封装,并且使用起来非常简单的一套 API,外号 “HTTP终结者”,用 Objective-C 编写,运行效率很高...
iphone 网络请求 类库 网络处理api iphone 开发必备类库程序源代码
网络请求第三方库的应用 asihttprequest
ASIHTTPRequest是简单易用的,它封装了...它是用Objective-C编写的,可以在MAC OS X和iPhone应用中使用。 它适用于执行基本的HTTP请求和互动(或者说是反馈)。ASIFormDataRequest子类可以简单的实现提交数据和文件。
该文章详细阐述了ASIHttpRequest的异步和同步请求,非常适合初学者
ios开发框架 ASIHttpRequest 资源来源于网上 非原创
ASIHTTPRequest 源码 、底层构架