【问题标题】:NSURLConnection hits didFailWithError when the URL actually exists当 URL 实际存在时,NSURLConnection 命中 didFailWithError
【发布时间】:2012-02-18 23:57:31
【问题描述】:

我正在尝试发送一个简单的 NSURLConnection 请求:

- (void) sendHTTPRequest:(NSString*)urlString
{
NSLog(@"SendHTTPRequest: %@", urlString);

@try
{
    NSURL *fileURL = [NSURL fileURLWithPath:urlString];

    // Create the request.        
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:fileURL            cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];

    NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:self];
    if (connection) {
        receivedData = [NSMutableData data];
    }
    else {
        // Inform the user that the connection failed.
    }
}
@catch (NSException *e)
{
    NSLog(@"Exception: %@", e);
}
}

它回调: - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error

出现错误:连接失败!错误 - 在此服务器上找不到请求的 URL。

但是,此网址确实有效。我可以用我的浏览器毫无问题地访问它。 我错过了什么?

【问题讨论】:

    标签: ios ios5 nsurlconnection nsurlrequest


    【解决方案1】:

    根据NSURL Class ReferencefileURLWithPath:path 仅用于有效的系统 路径。对于“Internet”-URL,您应该使用[NSURL urlWithString:urlString];

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-20
      • 1970-01-01
      • 2020-04-29
      • 2016-06-05
      • 1970-01-01
      • 1970-01-01
      • 2021-10-29
      • 1970-01-01
      相关资源
      最近更新 更多