zoukankan      html  css  js  c++  java
  • ASIHTTPRequest, request sent twice

    ´ve just started using ASIHTTPRequest for iOs and I have a small issue with it. All requests are sent twice to the server even though I only get one reply from the library to my delegate methods.

    Both sync and async requests have this issue. I use Xcode 4 with ARC but have disabled it for ASIHTTPRequest by adding -fno-objc-arc as compiler flags.

    Any idea what´s wrong..?

    Code:

    ASIHTTPRequest*request =[ASIHTTPRequest requestWithURL:url];[request startSynchronous];NSError*error =[request error];if(!error){}

    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.

  • 相关阅读:
    快速排序
    常见的正则表达式验证(更新中)
    中介者模式
    RadioButtonList控件如何取得选中的值
    职责链模式
    设计模式之GOF23建造者模式
    设计模式之GOF23工厂模式02
    设计模式GOF23之工厂模式01
    多线程测试时的辅助类--CountDownLatch
    设计模式GOF23之单例模式
  • 原文地址:https://www.cnblogs.com/lisa090818/p/3191624.html
Copyright © 2011-2022 走看看