Get Request: cURL error 7: couldn’t connect to host

Question

I am trying to make a GET request to a url from my wordpress installation to get the access token but I receive this error:

WP_Error Object ( [errors] => Array ( [http_request_failed] => Array ( [0] => cURL error 7: couldn’t connect to host ) ) [error_data] => Array ( ) )

If I make a get request to another url it works, if I make the same request from postman then it works again. If I paste the url in the browser I get {"error":"unsupported_grant_type"}. Only from the wordpress Installation it doesn’t work. I have tried with build in functions of wordpress and cURL but I always get the same cURL error 7: couldn't connect to host

Here is the code (similar with cUrl – same headers same body):

$response = wp_remote_request( 'https://subd.dom.mobi:5656/SyncServerAPI/token',
        [
            'headers'     => ['Content-type' => 'application/x-www-form-urlencoded'],
            'body' => [
                            'method' => 'GET',
                            'grant-type' => 'password',
                            'username' => 'usrnm',
                            'password' => 'pswrd',
                        ]
        ]
    );

    print_r($response);
0
, , rega stack 3 years 2020-05-29T18:10:51-05:00 0 Answers 100 views 0

Leave an answer

Browse
Browse