It shows 405 Server error at first time to get result from API server, and it works fine at second time

孤街浪徒 提交于 2019-12-08 04:32:36

问题


It shows 405 Server error at first time to get result from API server, and it works fine at second time. I've been trying to solve this issue for a month and couldn't find the solution.

I used Xcode 9.2, Swift 4, and Alamofire 4.6.

Main problem - API server logs suppose to show "POST" on http method. Howerver it shows only "ST" on http method. (This is the main problem.) This caused to get 405 server error.

My Source Codes using Alamofire

Alamofire.request(url, method: .post  , parameters: [“phone”:”123123”],encoding: JSONEncoding.default)
  .validate()
  .responseJSON { (response) in
  if response.result.isSuccess {
    success(response.result.value as! Dictionary)
 } else {
 LogHelper.printLog("response : \(response)")

    fail(response.result.error)
 }
}

What I have tried so far:

  • I added "application/json" on header => nothing changed.
  • I changed Alamofire versions and reinstalled it. => nothing changed.
  • Parameter Key change => 405 error and 500 error
  • Parameter value change => 405 error at first time, and success at second time request.
  • Alamofire econding change => nothing changed.
  • remove ".validate()" on Alamofire request. => nothing changed.
  • change to responseString from responseJSON => nothing changed.

回答1:


The current behaviour, where NSURLSession sends the Content-Length header but not the message body.

check this link: https://github.com/Alamofire/Alamofire/pull/2887



来源:https://stackoverflow.com/questions/48654888/it-shows-405-server-error-at-first-time-to-get-result-from-api-server-and-it-wo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!