【问题标题】:Bad URL when requesting with NSURL使用 NSURL 请求时出现错误的 URL
【发布时间】:2011-06-09 01:49:18
【问题描述】:

我正在尝试在 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 中复制和粘贴时,它可以工作。我尝试按照建议的here| 替换为%|,但不起作用。

从终端询问它看起来像这样:

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

有什么想法吗?

【问题讨论】:

标签: iphone objective-c ios4 nsurlrequest


【解决方案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"];

【讨论】:

  • 嗨 minu,我也遇到了关于错误 url 的问题,并发现编码是必须的
【解决方案2】:

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

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

【讨论】:

    【解决方案3】:

    嗬嗬嗬。

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

    这让我浪费了很多时间。

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

    【讨论】:

      【解决方案4】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-20
        • 2015-09-24
        • 1970-01-01
        • 2016-08-25
        相关资源
        最近更新 更多