你好 我正在使用 ASIHTTPRequest 向服务器发送一些值。一切正常,直到昨天 requestFinished 不起作用。 (当应用程序在服务器上发送请求时,事件指示器和添加到主视图的新 View 以及请求完成时删除 View )。我添加了 requestFailed 来测试是否失败,并收到此错误:
[3438:207] 错误域=ASIHTTPRequestErrorDomain 代码=2“请求超时”UserInfo=0x5ad25c0
这很奇怪,因为相同的代码昨天运行良好。我确信他们没有在服务器端进行任何更改。
这是代码:
- (IBAction)convert:(id)sender{
//Get the email from the textfield
NSString *email1 = email.text;
//Save the last used email to load it on the next app launch
[[NSUserDefaults standardUserDefaults] setValue:email1 forKey:@"email"];
//Get the current URL from webview
NSString *currentURL= webView.request.URL.relativeString;
lbl.text = currentURL;
//Count the length of Label
int strL= [lbl.text length];
//The url that the requests will be send.
NSURL *url = [NSURL URLWithString:@"the website"];
//Indicator and its view are loading on the screen
[ind startAnimating];
[self.view addSubview:indView];
//ASIHTTPRequests
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
NSString *watch = [lbl.text substringWithRange:NSMakeRange(23,strL-23)];
NSString *link = [NSString stringWithFormat:@"http://youtube.com/%@",watch];
[request setShouldRedirect:YES];
[request setPostValue:watch forKey:@"url"];
[request setPostValue:email1 forKey:@"email"];
[request setPostValue:format forKey:@"format"];
[request setPostValue:quality forKey:@"quality"];
[request setDelegate:self];
[request startAsynchronous];
NSLog(@"%@ %@ %@ %@",watch,email1,format,quality);
click=NO;
} 这是请求完成:
- (void)requestFinished:(ASIFormDataRequest *)request{
NSString *responseString = [request responseString];
NSLog(@"%@",responseString);
NSLog(@"%@",lbl.text);
NSLog(@"requested finished");
[ind stopAnimating];
[indView removeFromSuperview];
[setView removeFromSuperview];
}
最佳答案
您是否尝试增加请求的超时值?默认情况下为 10 秒,您可以通过在 startAsynchronous 调用之前执行此操作来使其更大:
[request setTimeOutSeconds:60];
关于iphone - ASIHTTP请求超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5863005/