MahmutTariq
MahmutTariq

Reputation: 237

Alamofire 4 sends method as POST but server reads it GET

I have a very weird problem here, using Alamofire 4 Swift 4 Xcode 9.1

let manager = Alamofire.SessionManager.default

    manager.session.configuration.timeoutIntervalForRequest = 30
    manager.session.configuration.requestCachePolicy = .reloadIgnoringLocalAndRemoteCacheData

    let request = manager.request(
        url,
        method: HTTPMethod.post,
        parameters: [:])

But server replies with method not allowed because it reads it as GET, however, if I change HTTPMethod.put or .delete or any other method, the server reads it correctly, the problem is with post specifically!

By debugging Alamofire's class 'SessionManager', specially the following method:

open func request(
    _ url: URLConvertible,
    method: HTTPMethod = .get,
    parameters: Parameters? = nil,
    encoding: ParameterEncoding = URLEncoding.default,
    headers: HTTPHeaders? = nil)
    -> DataRequest

The method here is correct, POST, so it's just fine before it goes out the application, what's wrong?

Upvotes: 0

Views: 131

Answers (1)

MahmutTariq
MahmutTariq

Reputation: 237

It was adding '/' at the end of the URL that was causing this.

Upvotes: 1

Related Questions