0

when i try to use Shodan API in pure php with curl for searching , nothing happen . my php code with curl:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://api.shodan.io/shodan/host/search?key=myapikey&query=apache&facets={}');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

$do = curl_exec($ch);
$do1 = json_decode($do,true);
curl_close($ch);


print_r($do1);
}
  • So what is the problem ? and it is always possible to use API with curl ?
demon666
  • 27
  • 6
  • What does "blank page" mean? Have you tried debugging it? What does `$do1` contain? Is the line printing it even reached? – Nico Haase Apr 09 '18 at 08:13
  • If I request that API URL in a browser, I get an 403 unauthorized message. You maybe just have forgot to login to that API service. See: https://stackoverflow.com/questions/3044315/how-to-set-the-authorization-header-using-curl – feeela Apr 09 '18 at 08:18
  • @NicoHaase , it means nothing happen , and $do1 for decode json response , – demon666 Apr 09 '18 at 08:18
  • @feeela no its ok , i can use that api without login . – demon666 Apr 09 '18 at 08:20
  • And the line with `print_r` is surely reached without problems? Have you tried debugging the cURL request, like explained at https://blog.kettle.io/debugging-curl-requests-in-php/? – Nico Haase Apr 09 '18 at 08:26
  • @NicoHaase , dude when i debugging the curl requests , this is what i get .. * Trying 216.117.2.180... * TCP_NODELAY set * Connected to api.shodan.io (216.117.2.180) port 443 (#0) * ALPN, offering http/1.1 * Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH * NPN, negotiated HTTP1.1 * SSL certificate problem: unable to get local issuer certificate * Curl_http_done: called premature == 1 * Closing connection 0 – demon666 Apr 09 '18 at 08:50
  • 1
    @NicoHaase Thanks aLot Its Solved by Debugging the Request and The Problem was in SSL .Ty – demon666 Apr 09 '18 at 09:10

0 Answers0