`
wsqwsq000
  • 浏览: 675433 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

iPhone使用ASIHTTPRequest请求时,发送了2次请求

阅读更多

 

 

前段时间用到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;

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics