0

I am creating a PHP curl request to server and expecting some string in response but no response generating , What may be the reason for that?

Below is the Curl code for the same:

$fields = array("username"=> 'xxx',"domain"=> 'xxx',"password" => 'xxx');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://host:8090/add-user"); 
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);     
curl_setopt($ch, CURLOPT_USERPWD, $usr.':'.$pass);
curl_setopt($ch, CURLOPT_POST, 1);      
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);   
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);    
if(!$result=curl_exec($ch)){ 
    trigger_error(curl_error($ch)); 
} 
curl_close($ch);
var_dump($result);

Below is equivalent command line request for the same:

curl --data 'username=xxx&domain=xxx&password=xxx' https://host:8090/add-user -k -v -u 'usr:pass'

What i am doing Wrong Here?

Explorer
  • 177
  • 6
  • 17

1 Answers1

1

You should first try to use curl_setopt($ch, CURLOPT_VERBOSE, $file_handler); where $file_handler = fopen('somefile.log', 'a'). Thus you will see what exactly cURL does, and where it fails.

Damaged Organic
  • 8,175
  • 6
  • 58
  • 84
  • Thanks.. Actually response is returned through headers.. using curl_getinfo($ch, CURLINFO_HTTP_CODE); solved the issue. – Explorer Nov 28 '13 at 10:21