0

我在我的 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 ,但有时会遇到两次或更多。你能帮助我吗?谢谢大家!

4

2 回答 2

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];
于 2012-06-27T09:36:58.103 回答
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;

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

我认为这可能会帮助你

于 2012-06-27T10:01:03.490 回答