【问题标题】:NSURLRequest - Request a url with more than 300 charactersNSURLRequest - 请求一个超过 300 个字符的 url
【发布时间】:2012-01-01 21:09:00
【问题描述】:

我想执行以下请求

NSString* testString = @"http://www.abcd.com?xxxxxxxxxxxxxxxxxx........." (The length of testString is more than 400 characters)
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:testString]];

如果我尝试上述 sn-p,则 urlRequest 将作为 NULL 值发送。有没有可能压缩字符串或URL???

【问题讨论】:

    标签: objective-c ios


    【解决方案1】:

    传递给 URL 的 NSString 长度没有限制,但有特殊字符可以做到这一点,例如空格、重音符号等。

    试试看:

    [NSURL URLWithString:[testString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];
    // if it`s using utf8
    

    更多详情在this Q&A

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-14
      • 2015-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-29
      • 2011-09-12
      • 1970-01-01
      相关资源
      最近更新 更多