【问题标题】:Error using NSURLConnection?使用 NSURLConnection 出错?
【发布时间】:2011-07-07 11:22:52
【问题描述】:

我正在使用以下代码

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];

当我运行项目时出现以下错误

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


 }

错误如下

 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."}

【问题讨论】:

  • 这个错误是因为数据连接不可用。
  • 它是否与另一个 URL(例如 apple.com)一起使用?

标签: iphone ipad nsurlconnection


【解决方案1】:

http://newdev.objectified.com/timvaughn/index.php?option=com_objmobadaptor 似乎需要身份验证。你实现了吗

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

?如果您不进行身份验证,请求将超时并导致您的错误。

【讨论】:

    【解决方案2】:

    如果您正在调试并且您将超时设置得很低,您可能会遇到这种情况。尝试增加超时或不使用断点运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-02
      • 2023-03-09
      相关资源
      最近更新 更多