我想获取 html 页面并对其进行解析。
我发送到http://gdata.youtube.com/feeds/api/videos?q=u_dAYLIG984
NSURL* url = [NSURL URLWithString: fullPath];
NSMutableDictionary* headers = [[[NSMutableDictionary alloc] init] autorelease];
[headers setValue:@"application/x-www-form-urlencoded;charset=utf-8" forKey:@"Content-Type"];
[headers setValue:@"text/html" forKey:@"Accept"];
[headers setValue:@"no-cache" forKey:@"Cache-Control"];
[headers setValue:@"no-cache" forKey:@"Pragma"];
[headers setValue:@"close" forKey:@"Connection"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:TIMEOUT_REQUEST];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
conn = [[NSURLConnection alloc] initWithRequest:request delegate:delegate startImmediately:YES];
我总是收到 403 错误。怎么了 ?
编辑:
我在http://bbc.co.uk/上尝试了我的请求,效果很好。我的问题只有http://gdata.youtube.com/feeds/api/videos?q=u_dAYLIG984
编辑2:
@Christophe Debove,你是对的。我将请求从 POST 更改为 GET 并收到 406 错误。当我删除“接受”标题时它开始工作。即使没有谷歌开发者密钥,它也可以工作。