2017-03-14 5 views
0

Ich versuche diese Curl-Anfrage mit PHP http-Build-Abfrage, aber es funktioniert nicht.PHP cURL mit 'Application/JSON' als Header

curl -H "Content-Type: application/json" -X POST -d '{"crawlDepth": 1, "url": "http://testphp.vulnweb.com/artists.php?artist=1"}' http://127.0.0.1:8775/scan/ 

Wie ist der beste Weg, um diese Anfrage zu erstellen?

Antwort

1
$data = array("crawlDepth" => 1, "url" => "http://testphp.vulnweb.com/artists.php?artist=1"); 
$data_string = json_encode($data); 

$ch = curl_init('http://127.0.0.1:8775/scan/'); 

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',  
    'Content-Length: ' . strlen($data_string)) 
);           

$result = curl_exec($ch);