Bad URL when requesting with NSURL

喜欢而已 提交于 2019-11-26 17:48:16

问题


I'm trying to request this kind of URL in iPhone 4.0 SDK (access token slightly modified because you don't really need to see it):

https://graph.facebook.com/me?sdk=ios&sdk_version=2&access_token=123902817987|8cb9e8408d2685cef853cd80.9-747882379|UGu5NvcAHiXuGEGzkq&format=json&limit=40&until=1286619821

But I got this message:

Failed with error: Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0x9e657a0 {NSUnderlyingError=0x9e656a0 "bad URL", NSLocalizedDescription=bad URL}

When I copied and pasted in Safari or Chrome, it works. I tried replacing | with %| as suggested here but doesn't work.

Asking it from the terminal looks like this:

curl https://graph.facebook.com/me/statuses?sdk=ios&sdk_version=2&access_token=9999955817987|8ab9e8408d2685cef.3-747882379|UGuxWDuM&format=json&limit=40&until=1286619821
[1] 16190
[2] 16191
[3] 16194
[4] 16195
[5] 16196
[2]   Done                    sdk_version=2
[4]-  Done                    format=json
$ -bash: UGu5NvcAHiXuGEGzkq3KP8xWDuM: command not found
-bash: 8ab9e8408d2685cef853cd80.3-747882379: command not found
{"error":{"type":"OAuthException","message":"An active access token must be used to query information about the current user."}}
[1]   Done                    curl https://graph.facebook.com/me/statuses?sdk=ios
[3]-  Exit 127                access_token=9999955817987 | 8ab9e8408d2685cef.3-747882379 | UGuxWDuM
[5]+  Done                    limit=40

Any ideas?


回答1:


 NSString *strURL = [loc_address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

            // requesting weather for this location ... 
            NSMutableURLRequest *req = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat: @"http://www.google.com/ig/api?weather=%@", strURL]] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:5.0];
            [req setHTTPMethod:@"POST"];
            [req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];



回答2:


You need to replace the pipe character in the URL with %7C. This is the URL encoded value.

Also, the URL needs to be enclosed in quotation marks in order for it to work with curl.




回答3:


ho ho ho.

Set location_id using the id of the venue you want.

This make me waste a lot of time.

One of dozen facebook secrets is debug network when making what you want, in this case creating a event. You'll see the correct params names for what you need.




回答4:


This error message, also can be caused by any error in the URL typing. Usually some white space in the URL string.



来源:https://stackoverflow.com/questions/6287230/bad-url-when-requesting-with-nsurl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!