【发布时间】: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