0

Php curl always return TRUE. Though data send in request is wrong and at server side its showing error HTTP 400 -Bad request. here, is my sample code. It should have returned FALSE.

 $curl = curl_init($url);

 curl_setopt($curl,CURLOPT_CUSTOMREQUEST,"PUT");
 curl_setopt($curl, CURLOPT_HTTPHEADER,$headers);
 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
 curl_setopt($curl,CURLOPT_POSTFIELDS,$update_para);
 $curl_response = curl_exec($curl);
1
  • You have not specfied your url here. May be something wrong in url. Commented Mar 4, 2016 at 11:02

1 Answer 1

2

I'm not sure when exactly curl_exec will return false but when the request is sent and response is returned it's certainly not a failure, so it returns true - as in "I've managed to send the request and got a response". What is the result of the request on the server-side and contents of the response is completely different thing.

Use CURLOPT_RETURNTRANSFER => true to capture the response data, and curl_getinfo to get other informations, for example http_code.

When result of curl_exec is false use curl_errno and/or curl_error to examine what went wrong when trying to send a request.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.