Search code examples
iphoneiosasihttprequestresponse

ASIHTTPRequest iOS call once but response many times


I got a problem with ASIHTTPRequest in my iOS project. I start a request but sometimes it response twice or more.

When I start request:

 [request addRequestHeader:@"User-Agent" value:@"ASIHTTPRequest"]; 
[request addRequestHeader:@"Content-Type" value:@"application/json; charset=utf-8"];
[request setRequestMethod:@"GET"];
request.timeOutSeconds = 60;
[request setShouldAttemptPersistentConnection:NO];
[request setDelegate:self];
[request setDidFinishSelector:@selector(getListProduct_OnSuccess:)];
[request setDidFailSelector:@selector(getListProduct_OnError:)];
[request startAsynchronous];

but it run into getListProduct_OnSuccess sometimes once, but sometimes twice, or more. Can you help me? Thanks all!


Solution

  • Use this ASIHTTPRequestDelegate methods,

    // These are the default delegate methods for request status
    // You can use different ones by setting didStartSelector / didFinishSelector / didFailSelector
    
    - (void)requestFinished:(ASIHTTPRequest *)request; 
    
    - (void)requestFailed:(ASIHTTPRequest *)request;
    

    And inside these methods you can set your selector methods.

    I think this may help you