Question

I want to get html page and parse it.

I send to 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];

I always get 403 error. What is wrong ?

EDITED:

I tried my request on http://bbc.co.uk/ and it works well. My problem only with http://gdata.youtube.com/feeds/api/videos?q=u_dAYLIG984

EDITED2:

@Christophe Debove, you are right. I changed my request from POST to GET and received 406 error. It became working when I deleted "Accept" header. It works even without google developer key.

Était-ce utile?

La solution

It seems server forbid you. It can happen when you forget to pass security parameters or you're wrong with some headers values.

HTTP code 403   Forbidden 

I try to send the request with LiveHTTPHeader the firefox module. And I saw youtube api doesn't accept POST request but only GET.

When I send with POST method I get 403 forbiden Target feed is read-only

So please change the method with GET

[request setHTTPMethod:@"GET"];

you can remove some of your headers value even if they don't cause the pb there are useless.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top