使用 NSURL 请求时 URL 错误

发布于 2024-11-14 17:40:32 字数 1558 浏览 2 评论 0原文

我试图在 iPhone 4.0 SDK 中请求这种 URL(访问令牌稍作修改,因为您实际上不需要看到它):

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

但我收到此消息:

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

当我在 Safari 或 Chrome 中复制并粘贴时,它可以工作。我尝试按照建议将 | 替换为 %| 此处 但不起作用。

从终端询问是这样的:

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

有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

往事随风而去 2024-11-21 17:40:32
 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"];
 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"];
只是偏爱你 2024-11-21 17:40:32

您需要将 URL 中的管道字符替换为 %7C。这是 URL 编码值。

此外,URL 需要用引号括起来,以便与curl 一起使用。

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.

暗藏城府 2024-11-21 17:40:32

嗬嗬嗬。

使用您想要的地点的 ID 设置 location_id

这让我浪费了很多时间。

Facebook 的十几个秘密之一是在制作你想要的东西时调试网络,在本例中创建一个事件。您将看到所需的正确参数名称。

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.

甜中书 2024-11-21 17:40:32

此错误消息也可能是由 URL 输入中的任何错误引起的。 URL 字符串中通常有一些空格。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文