I am trying to send a simple NSURLConnection request:
- (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);
}
}
It calls back to:
– (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
with an error of: Connection failed! Error – The requested URL was not found on this server.
However, this url does work. I can access it with my browser with no issues.
What am I missing?
According to the NSURL Class Reference,
fileURLWithPath:pathis only used for valid system paths. For “Internet”-URLs, you are supposed to use[NSURL urlWithString:urlString];