4

这仅出现在 iOS 8 上。对于早期版本,这很好。

例子:

对于 iOS 7.1:

NSString *url = @"http://www.example.com/api/search?name=test&page=1";
NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] init];
[urlRequest setURL:[NSURL URLWithString:url]];

成为urlRequest_

<NSMutableURLRequest: 0x7b787130> { URL: http://www.example.com/api/search?name=test&page=1 }

对于 iOS 8.0:

NSString *url = @"http://www.example.com/api/search?name=test&page=1";
NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] init];
[urlRequest setURL:[NSURL URLWithString:url]];

成为urlRequest_

<NSMutableURLRequest: 0x7b6246d0> { URL: http://www.example.com/api/search?name=test&page=1, headers: (null) }

iOS 8.0 的错误:Error 400 (Bad Request)

4

1 回答 1

0

你误解了那个日志。这只是意味着

URL = "http://www.example.com/api/search?name=test&page=1"

headers = null

您应该调试的是实际的标头:

NSLog("%@", urlRequest.allHTTPHeaderFields);
于 2014-09-22T10:27:07.503 回答