Error using NSURLConnection?

穿精又带淫゛_ 提交于 2019-12-11 07:39:58

问题


I am using following code

NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:listUrl]
                                          cachePolicy:NSURLRequestUseProtocolCachePolicy
                                      timeoutInterval:180.0];

// create the connection with the request
// and start loading the data
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

xmlData=[[NSMutableData alloc]init];

and when I run the project get follwing error in

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
   NSLog(@"ERROR with theConenction %@",error);


 }

error is as follows

 2011-07-07 16:17:12.343 Tim Vaughn[722:707] ERROR with theConenction Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo=0x1b8b10 {NSErrorFailingURLStringKey=http://newdev.objectified.com/timvaughn/index.php?option=com_objmobadaptor, NSErrorFailingURLKey=http://newdev.xxxxx.com/xxxxxx/index.php?option=com_objmobadaptor, NSLocalizedDescription=The request timed out., NSUnderlyingError=0x1bb610 "The request timed out."}

回答1:


http://newdev.objectified.com/timvaughn/index.php?option=com_objmobadaptor seems to need authentication. Did you implement

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;

? If you don't authenticate, the request will timeout and that causes your error.




回答2:


You might run into this if you are debugging and you have your timeout set low. Try increasing your timeout or run without breakpoints.



来源:https://stackoverflow.com/questions/6609813/error-using-nsurlconnection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!