Just My Life & My Work

呼叫 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)

隨意留個言吧:)~

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com 標誌

您的留言將使用 WordPress.com 帳號。 登出 /  變更 )

Google photo

您的留言將使用 Google 帳號。 登出 /  變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 /  變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 /  變更 )

連結到 %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

標籤雲

%d 位部落客按了讚: