【问题标题】:ASIHTTPRequest time outASIHTTPRequest 超时
【发布时间】:2011-05-02 22:07:33
【问题描述】:

你好 我正在使用 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];

}

【问题讨论】:

  • 将 URL 弹出到浏览器中时是否显示页面?
  • 是的。我正在向服务器发送有关 youtube 链接的详细信息,然后服务器将它们发送到其他服务器上。直到昨天,请求还可以,因为我正在从服务器获得响应。今天,服务器遵循重定向并继续在 2-3 分钟后回复的另一台服务器(取决于 youtube 视频的大小)。当我使用一个小视频的 youtube 链接并在超时之前从第二台服务器获得回复时,我意识到这一点。我尝试设置 shouldRedirect:NO 但什么也没有。奇怪的是昨天一切正常

标签: iphone timeout asihttprequest


【解决方案1】:

您是否尝试增加请求的超时值?默认为 10 秒,您可以在 startAsynchronous 调用之前将其变大:

[request setTimeOutSeconds:60];

【讨论】:

  • 这对我有用,谢谢!同样的问题,正在运行的代码刚刚开始失败。我知道这一定是由于网络延迟或其他原因暴露的代码中的一些弱点,看起来这就是问题所在。
  • 不适合我,我将超时设置为 200 秒,然后在 75 秒后超时....有什么想法吗?
  • 此时,我建议切换到 AFNetworking,因为该项目仍在积极开发中。转换内容需要一些工作,但对我来说,在使用网络的应用程序中这样做是非常值得的。
猜你喜欢
  • 2013-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多