iOS 请求出现 "Request failed: bad request (400)"
主要出现如下错误:
请求失败-Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: bad request (400)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7cec30d0> { URL: https://api.weibo.com/oauth2/access_token } { status code: 400, headers {
"Cache-Control" = "no-cache";
Date = "Sat, 07 Nov 2015 01:07:18 GMT";
Expires = "Thu, 01 Jan 1970 00:00:00 GMT";
Pragma = "No-cache";
Server = "nginx/1.6.1";
"api-server-ip" = "10.75.25.115";
} }, NSErrorFailingURLKey=https://api.weibo.com/oauth2/access_token, NSLocalizedDescription=Request failed: bad request (400), com.alamofire.serialization.response.error.data=<7b226572 726f7222 3a22696e 76616c69 645f6772 616e7422 2c226572 726f725f 636f6465 223a3231 3332352c 22726571 75657374 223a222f 6f617574 68322f61 63636573 735f746f 6b656e22 2c226572 726f725f 75726922 3a222f6f 61757468 322f6163 63657373 5f746f6b 656e222c 22657272 6f725f64 65736372 69707469 6f6e223a 22696e76 616c6964 20617574 686f7269 7a617469 6f6e2063 6f64653a 36356464 33643966 63626462 65616664 66343963 32336438 36663832 36313931 2666726f 6d3d3834 34622676 69743d66 7073227d>}
解决办法:
Check for errors in the URL. The most common reason for a 400 Bad Request error is because the URL was typed wrong or the link that was clicked on points to a URL with a specific kind of mistake in it, like a syntax problem.
检查URL里面的错误。400错误请求错误最常见的原因是由于URL输入错误或点击的链接指向一个URL和一种特定的错误,比如语法问题。
Important: This is most likely the problem if you get a 400 Bad Request error. Specficially, check for extra, typically non-allowed, characters in the URL like a percentage character. While there are perfectly valid uses for something like a % character, you won't often find one in a standard URL.
重点:这是最可能出现的问题如果你得到一个400错误请求错误。尤其,检查在URL中一些典型的字符,比如%字符。像%字符在一些地方能够被有效使用,你不会在标准URL中就发现一个。