您好我正在使用ASIHTTPRequest向服务器发送一些值.所有工作都很好,直到昨天requestFinished没有工作.(当应用程序在服务器上发送请求时,活动指示符和添加到主视图的新视图以及请求完成时删除视图).我添加了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;
这是requestFinished:
- (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];