Search code examples
objective-cnsurlrequestcraigslist

NSURLRequest, why does craigslist return a 404?


I'm building my first iPhone app and I'm stymied.

I'm trying to build an RSS reader, and I'm trying to use a feed from craigslist. This code, using stackoverflow, returns "Status code: 200":

- (void)parseRSSFeed:(NSString *)feed withDelegate:(id)delegate
{
 responseData = [[NSMutableData data] retain];
 feed = @"http://stackoverflow.com";
 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:feed]];
 [[NSURLConnection alloc] initWithRequest:request delegate:self]; 
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
 NSLog(@"status code: %d", [((NSHTTPURLResponse*) response) statusCode]);
 [responseData setLength:0];
}

All is well. But if I change feed to, say, "http://portland.craigslist.org/muc/", I get a status code of 404.

Is there anything I'm missing? Does Craigslist disallow iPhone access to its website? Is there some escaping I need to do on the URL?

The code, with the craigslist URL, is here. This is exactly as I'm using it, and it returns a 404:

- (void)parseRSSFeed:(NSString *)feed withDelegate:(id)delegate
{
 responseData = [[NSMutableData data] retain];
 feed = @"http://portland.craigslist.org/muc/";
 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:feed]];
 [[NSURLConnection alloc] initWithRequest:request delegate:self]; 
}

Solution

  • Ok i figured it out. Craigslist is blocking this request. The same code works when you change the name of the app. For example when the app name contained the string "craig" the response code that was returned was 404. When i changed the app name to not contain the name "craig" then the response is 200.