0

I'm executing a curl request using php:

 //Initiate cURL. $ch = curl_init($url); //Encode the array into JSON. $jsonDataEncoded = json_encode($data); //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); 

The browser returns:

{"success":"true","lead_id":"141872","code":201} OR {"error":true,"duplicate":true,"message":"Duplicate: This has already been submitted to the API.","code":400} 

How do I access the data in $result it current only returns 1

2 Answers 2

2

Set return transfer to true to get the page response in $result

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
Sign up to request clarification or add additional context in comments.

Comments

1
$options = array ( CURLOPT_CONNECTTIMEOUT => 1, // timeout on connect CURLOPT_TIMEOUT => 1, // timeout on response CURLOPT_MAXREDIRS => 1 , CURLOPT_HTTPHEADER => array("REMOTE_ADDR: $proxy", "HTTP_X_FORWARDED_FOR: $proxy"), CURLOPT_URL => $url ); $ch = curl_init(); curl_setopt_array ( $ch, $options ); $result = curl_exec($ch); print_r($result); curl_close($ch); 

your solution :

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.