1

I am trying to send a POST request using cURL.

When I do this in POSTMAN(see screenshot)I get HTTP status 400 (which is fine).

enter image description here

However when I do this in the following cURL I get HTTP status 0 and error Could not resolve: hello.net (DNS server returned answer with no data). Anyone know why?

<?php

$url = 'https://hello.net/';

$ch = curl_init($url);

$postdata = array(
                "vendorCode"=>"12345",
                "email" => "john.smith@gmail.com",
                "name" => "john ",
                "organization" => "company.org.id",
                "organizationUser" => "john.smith.id",
                "accountName"=> "company",
                "launchProp" => array(
                    "launchprop" => "ext",
                    "platform" => "web"
                ),
                "authorizationType"=> "jwt"
        );

$jsonDataEncoded = json_encode($postdata);

//Tell cURL that we want to send a POST request.
curl_setopt($ch, CURLOPT_POST, 1);

//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);

//Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 

//Execute the request
$result = curl_exec($ch);

$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo $http_status, PHP_EOL;
?>

UPDATE: When I put URL google.com I get error 405.

user1163234
  • 2,407
  • 6
  • 35
  • 63
  • 2
    A zero status code from Curl normally implies that the connection couldn't be made at all, for example if the host name could not be found. Try printing `curl_error($ch);` – iainn Jan 31 '21 at 16:47
  • Im getting "Could not resolve: hello.net (DNS server returned answer with no data)" – user1163234 Jan 31 '21 at 16:59
  • There's clearly no record of that URL at the DNS server used by the machine where PHP is running. Therefore it does not know where to route the request – ADyson Jan 31 '21 at 18:39
  • Anything I need to do? Do I need to configure my php.ini ? Other post requests work so im confused... – user1163234 Jan 31 '21 at 19:06
  • php.ini has nothing to do with it, no. Do you understand what a DNS record is? Or a DNS server? https://stackoverflow.com/questions/24967855/curl-6-could-not-resolve-host-google-com-name-or-service-not-known might help you, it's for a very similar error (on a different URL, but the principle is the same) – ADyson Jan 31 '21 at 22:00

0 Answers0