3

I want to use jsonWhois api but it makes the server request using Unirest, which looks like it's no longer maintained and I would prefer to use curl anyway.

How can I convert this code to use Curl instead??

$response = Unirest\Request::get("https://jsonwhois.com/api/v1/whois", 

   array(
    "Accept" => "application/json",
    "Authorization" => "Token token=<Api Key>"
   ),

   array(
       "domain" => "google.com"
   )

);

$data = $response->body; // Parsed body

I've tried curl_setopt($ch, CURLOPT_URL, 'https://jsonwhois.com/api/v1/whois?token=123456&domain=google.com');, but it says HTTP Token: access denied.

turrican_34
  • 679
  • 1
  • 7
  • 27
  • 1
    Looking at the original code, it seems like the token needs to be sent in the header and not as a query param. – M. Eriksson Dec 09 '17 at 17:49

1 Answers1

1

You can actually use Postman app for something like this. I use it all the time and it works great.

You can simply enter the request into it:

request parameters

And then simply click on "Code" (top right corner) and go to "PHP" -> "cURL". It will show you the exact code that you have to write to make that request using cURL:

PHP cURL code

I have no idea what jsonwhois is but, if everything is set up correctly, it should work.

Radu Murzea
  • 10,724
  • 10
  • 47
  • 69