Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert unirest to curl

Tags:

php

curl

unirest

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.

like image 461
turrican_34 Avatar asked Dec 05 '25 18:12

turrican_34


1 Answers

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.

like image 118
Radu Murzea Avatar answered Dec 07 '25 07:12

Radu Murzea