ASIHTTPRequest iOS调用一次,但多次响应

时间:2012-06-27 08:11:16

标签: iphone ios asihttprequest response

我的iOS项目中出现ASIHTTPRequest问题。我开始请求但有时它会响应两次或更多次。

当我开始请求时:

 [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];

但它有时会遇到getListProduct_OnSuccess一次,但有时会两次或更多次。 你能帮助我吗?谢谢大家!

2 个答案:

答案 0 :(得分:0)

试试这个

NSURL *url = [NSURL URLWithString:@"yoururl"];    
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    [request setRequestMethod:@"POST"];
    [request setPostValue:email forKey:@"username"];
    [request setPostValue:pasw forKey:@"pass"];
    [request setDelegate:self];
    [request startAsynchronous];

答案 1 :(得分:0)

使用此ASIHTTPRequestDelegate方法

// 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;

在这些方法中,您可以设置选择器方法。

我认为这可能会对你有所帮助