php – POST requests not working in Swift with Alamofire



I’m trying to send data from a Swift app to a backend in PHP.
To test, I make a request via POST with Alamofire and print the request method as a response from the Server.

let URL_USER = "myurl"
var sampleRequest = URLRequest(url: URL(string: URL_USER)!)
sampleRequest.httpMethod =
AF.request(sampleRequest).uploadProgress{ progress in }.response(){
    response in
    if( != nil) {
        print(String(bytes:!, encoding: .utf8) as Any)
    else {

The PHP script:

    echo 'OK';
else {
    echo 'Wrong request method';

The server response is always Wrong request method

The same also occurs using the post parameter directly inside the Alamofire call, with this code:

AF.request("myurl", method: .post).response {...}

Any attempt to send the request via POST, even without Alamofire, fails and the server replies saying that the request is of type GET.

This occurs both on the simulator and on a real device, without any proxy.

The URL I call is based on https