Search code examples
swifthttppostgetalamofire

Swift Alamofire POST request becomes GET


That's the code I'm using to make POST request to my Flask server in localhost:

func data_request() {
    let url:NSURL = NSURL(string: "http://192.168.1.192:9880/api/register")!

    Alamofire.request(.POST, url, parameters: ["login":"login", "password" : "12345"]).responseJSON { response in
        switch response.result {
        case .Success:
            NSLog("Validation Successful")
        case .Failure(let error):
            NSLog("\(error), \(String(data: response.data!, encoding: NSUTF8StringEncoding))")
            return
        }
        if (response.result.value as? [String: AnyObject]) != nil{
            print(response.result.value)
        } 
    }
}

But it sends GET request! Both server and local proxy tell it was GET request - that's what Burp has intercepted:

GET /api/register/ HTTP/1.1
Host: 192.168.1.192:9880
Accept: */*
User-Agent: Project Manager/Roman-Nikitin.Project-Manager (1; OS X 10.11.3)
Accept-Language: en;q=1.0, fr;q=0.9, de;q=0.8, zh-Hans;q=0.7, zh-Hant;q=0.6, ja;q=0.5
Accept-Encoding: gzip;q=1.0, compress;q=0.5
Connection: close

Solution

  • I had the same problem, you just have to put / at the end of URL. Problem is in Alamofire, I think. It works weird with normal server redirections from www.domain.com/something to www.domain.com/something/