How Do i translate command line curl commang into PHP curl call? -
here command line command:
curl -h "authorization: bearer api_key" -x put https://graph.api.smartthings.com/api/smartapps/installations/device_id/lock
here have uptill now, wrong code:
$headers = array('authorization: bearer ' . $st_api_token); $ch = curl_init(); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_httpheader, $headers); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_verbose, true); curl_setopt($ch, curlopt_customrequest, 'put'); $response = curl_exec($ch); curl_close($ch);
output var_dump(curl_getinfo($ch));
is, still unable find real error or doing wrong in translating code php:
<?php array (size=26) url => string 'https://graph.api.smartthings.com/api/smartapps/installations/c8137097-8532-43b8-b516-0573cb91ecee/setlockcode/20/3333' (length=118) 'content_type' => null 'http_code' => int 0 'header_size' => int 0 'request_size' => int 0 'filetime' => int -1 'ssl_verify_result' => int 1 'redirect_count' => int 0 'total_time' => float 0.547 'namelookup_time' => float 0 'connect_time' => float 0.282 'pretransfer_time' => float 0 'size_upload' => float 0 'size_download' => float 0 'speed_download' => float 0 'speed_upload' => float 0 'download_content_length' => float -1 'upload_content_length' => float -1 'starttransfer_time' => float 0 'redirect_time' => float 0 'redirect_url' => string '' (length=0) 'primary_ip' => string '54.243.113.196' (length=14) 'certinfo' => array (size=0) empty 'primary_port' => int 443 'local_ip' => string '192.168.0.139' (length=13) 'local_port' => int 62555 ?>
after searching on internet got issue fixed changing headers array , adding curl settings:
$headers = array('authorization: bearer ' . $st_api_token, 'content-type: application/json', 'accept: json', ); $ch = curl_init(); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_httpheader, $headers); curl_setopt($ch, curlopt_customrequest, 'put'); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_verbose, true); curl_setopt($ch, curlopt_ssl_verifyhost , false); curl_setopt($ch, curlopt_ssl_verifypeer, false); $response = curl_exec($ch); curl_close($ch);
Comments
Post a Comment