Just My Life & My Work

Archive for 2021 年 10 月 05 日

呼叫 API 的 URL 過長問題

最近在整合 API,需要附加大量的參數,使用 Get 方式呼叫,發生:

Request failed: requested URL too long (414)


Two options to resolve the problem for 414 response code:

  1. By POST request: Convert query string to json object and sent to API request with POST
  2. By GET request: Max length of request is depend on sever side as well as client side. Most webserver have limit 8k which is configurable. On the client side the different browser has different limit. The browser IE and Safari limit to 2k, Opera 4k and Firefox 8k. means the max length for the GET request is 8k and min request length is 2k.
    If exceed the request max length then the request truncated outside the limit by web server or browser without any warning. Some server truncated request data but the some server reject it because of data lose and they will return with response code 414.

最後我改成 Post 方式呼叫,就再也沒有此問題!😃

iOS 回傳

Error Domain=com.alamofire.error.serialization.response Code=-1011 “Request failed: requested URL too long (414)" UserInfo={NSLocalizedDescription=Request failed: requested URL too long (414), 

Chrome 回傳

Request-URI Too Large
The requested URL’s length exceeds the capacity limit for this server.
Apache/2.2.15 (CentOS) Server at upload.tintint.com Port 443

參考:414 (Request-URI Too Long)


%d 位部落客按了讚: