Just My Life & My Work

Archive for 十月, 2021

[iOS] 判斷 NaN

進公司兩年,還是有一些 Bug/Crash 未解,不是我不想解,只是不知道如何「重現」。偶然間我終於可以持續重現狀況,趕緊放下手邊工作,接上手機編譯 App,在 Xcode 設中斷點,便能知道前後變數當前的值,推敲源頭是什麼~😗

當我重複進出某頁,就會 Crash🤪

呼叫 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 位部落客按了讚: