IOS开发之——ASIHTTPRequest请求时,发送了2次请求问题解决
2012-09-14 11:31
639 查看
相信很多朋友会遇到:使用ASIHTTPRequest GET请求时,发送了2次(即重复发送了1次)
由于之前的app都对失败,没有非常重要的要求,因此,也从没留意这个问题。这次产品升级,增加了一些新的需求,这些需求又恰好对这个要求较高,为这个问题纠结了一段时间后来组内老大网上找到答案,这是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.
相关文章推荐
- IOS开发之——ASIHTTPRequest请求时,发送了2次请求问题解决
- ASIHTTPRequest请求时,发送了2次请求问题解决
- ios开发中asihttprequest请求,汉字乱码问题的解决
- iOS开发ASIHttpRequest发送请求
- IOS开发 REST请求 ASIHTTPRequest用法
- iOS开发ASIHttpRequest发送数据
- IE浏览器中XMLHttpRequest对同一个URL只发送一个请求问题的解决。
- iOS开发ASIHttpRequest发送数据【3】
- iOS开发网络请求中ASIHTTPRequest的用法整理
- IOS中使用ASIHTTPRequest类库时出现的问题解决
- iOS 使用ASIHTTPRequest 发送Webservice请求
- ios开发之ASIHttpRequest-发送数据
- iOS开发asi使用(二)ASIHttpRequest发送数据
- iOS ASIHTTPRequest 多次重复请求的问题
- ASIHTTPRequest iOS7下内存泄漏问题解决记录
- iOS开发工具-如何使用网络封包分析工具Charles,通过配置proxy对http、https、tcp、udp 等协议的请求响应过程交互信息进行分析、判断、解决我们移动开发中的遇到的各种实际问题。
- iOS开发之网络请求(一)ASIHTTPRequest
- iOS总结:ASIHttpRequest类库发送请求(同步请求和异步请求)
- IOS 学习笔记 —— ASIHTTPRequest 之 发送异步请求
- IOS开发 REST请求 ASIHTTPRequest用法