NSURLRequest,为什么craigslist返回404? [英] NSURLRequest, why does craigslist return a 404?

查看:104
本文介绍了NSURLRequest,为什么craigslist返回404?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建我的第一个iPhone应用程序,但我受阻了.

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

我正在尝试构建RSS阅读器,并且正在尝试使用craigslist中的供稿.此代码使用stackoverflow返回状态码:200":

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

一切都很好.但是,如果我将供稿更改为"http://portland.craigslist.org/muc/",则状态码为404.

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

有什么我想念的吗? Craigslist是否禁止iPhone访问其网站?我需要对URL进行一些转义吗?

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?

带有craigslist URL的代码在这里.这与我正在使用的完全相同,它返回404:

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

推荐答案

好,我知道了. Craigslist阻止了此请求.更改应用程序名称时,相同的代码有效.例如,当应用程序名称包含字符串"craig"时,返回的响应代码为404.当我将应用程序名称更改为不包含名称"craig"时,响应为200.

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.

这篇关于NSURLRequest,为什么craigslist返回404?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆