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