1

Im using the following code to send a POST request to the web server with an http parameter, in order to receive the JSON Data

Alamofire.request(.POST,myURL, parameters: [:], encoding: .Custom({
        (convertible, params) in
        var mutableRequest = convertible.URLRequest.copy() as NSMutableURLRequest
        mutableRequest.HTTPBody = "MyBody".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
        return (mutableRequest, nil)
    }))

ive got it from stackoverflow : POST request with a simple string in body with Alamofire but im not receiving any data. im using swift 2.3 and alamofire 3.5.

Any help?

Community
  • 1
  • 1

1 Answers1

0

simple POST call with Alamofire4 & Swift3 :

    let url: String = "https://example.com"
    let parameter = ["X": "10", "Y": "20"]


    Alamofire.request(url, method: .post, parameters: parameter, encoding: URLEncoding.default, headers: nil)
        .responseJSON { (response) in

            let result = response.result.value
            print(result)

    }

simple GET call to see some JSON result :

        let url: String = "https://example.com"
        Alamofire.request(url)
        .responseJSON { response in

            let result = response.result.value
            print(result)
    }
Arafin Russell
  • 1,487
  • 1
  • 18
  • 37