Search code examples
iosswiftalamofire

Alamofire request changes method name on its own


I am using the following code:

func readInfo()
{
    let customHeader : HTTPHeaders = [
                "X-AUTH-TOKEN" : accessToken
            ]
    let body : Parameters = [
                :
            ]
    Alamofire.SessionManager.default.session.configuration.timeoutIntervalForRequest = 1000
    Alamofire.request(requestAddress, method: .get, parameters: body , encoding: JSONEncoding.default, headers: customHeader).responseJSON { 

    response in

     //utility code           

    }
}

It works perfect when this runs for the first time but when this is run more than once (in say less than 30 seconds), my server gives the error: o.s.web.servlet.PageNotFound : Request method 'T' not supported

Also I get status code 405 in Alamofire response. This is unexpected since I was sending .get request. Why is this happening and how should I avoid it? I am unable to understand.

Also, note that this is not a server error because the requests work as expected when run on Postman.


Solution

  • There were no errors with the cache or timeout. The error was with encoding. I had to save it to URLEncoding.httpBody to make the request work as expected. I still don't understand why it worked once and not for the second time for a certain seconds. Strange case but yes this was the solution. Please leave a comment to help me and others understand why this may have happened.