【问题标题】:Returning a NSMutableURLRequest with a url that contains quotes返回带有包含引号的 url 的 NSMutableURLRequest
【发布时间】:2014-01-31 00:17:31
【问题描述】:
NSString *urlString = @"http://example.com/myzip?\"30339\"";
NSLog(@"urlstring: %@", urlString);
// RETURNS=> urlstring: http://example.com/myzip?"30339"
NSURL *url = [NSURL URLWithString:urlString];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
NSLog(@"request: %@", request);
// RETURNS=> request: <NSMutableURLRequest: 0x8f54480> { URL: (null) }

如果我的 URL 中包含引号,我将无法完成 NSMutableURLRequest。有解决办法吗?

【问题讨论】:

    标签: nsstring nsurl


    【解决方案1】:

    " 不是用于 URL 的合法字符,必须转义(如 %22),如下所示:

    http://example.com/myzip?%2230339%22
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-09
      • 1970-01-01
      • 1970-01-01
      • 2012-03-02
      • 1970-01-01
      • 2020-02-11
      相关资源
      最近更新 更多