Could not resolve host on cURL request PHP -


i'm starting build first api, after succesful testing on localhost(mac os x el capitan) uploaded digitalocean server running ubuntu 16.04.

i've both tried run curl request localhost , server api stored , both of them return "could not resolve host" error error number 6. code:

on api side just

echo "200";exit; 

on client side

$token = 'this session token'; $url = "http://xx.xx.xx.xx/api/index.php"; $data = array('username'=>'username','password'=>'password'); $datajson = json_encode($data);  $message = $url . $datajson . 'put'; $publishthis = base64_encode(         hash_hmac('sha256', $message, 'secret key', true)     );     $len = 'content-length: ' . strlen($message); $ch = curl_init();     curl_setopt($ch, curlopt_url, urlencode($url));     curl_setopt($ch, curlopt_httpheader, array('content-type: application/json',$len, 'authorization: ' . $publishthis));     curl_setopt($ch, curlopt_customrequest, 'put');     curl_setopt($ch, curlopt_postfields,$datajson);      curl_setopt($ch, curlopt_returntransfer, true);     curl_setopt($ch, curlopt_header, true);     $response  = curl_exec($ch); 

help please!!

p.s: if remove urlencode function request takes 20 mins , ends on 400 bad request error

later edit:

$token = 'this session token'; $url = "http://xx.xx.xx.xx/api/index.php"; $data = array('username'=>'username','password'=>'password'); $datajson = json_encode($data); $build_query = http_build_query($data);  $message = $url . $datajson . 'put'; $publishthis = base64_encode(         hash_hmac('sha256', $message, 'secret key', true) ); $len = 'content-length: ' . strlen($build_query); $ch = curl_init(); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_httpheader, array('content-type: application/json',$len, 'authorization: ' . $publishthis)); curl_setopt($ch, curlopt_customrequest, 'put'); curl_setopt($ch, curlopt_postfields,$build_query); curl_setopt($ch, curlopt_verbose, true); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_header, true); $response  = curl_exec($ch);  if($errno = curl_errno($ch)) {     $error_message = curl_strerror($errno);     echo "curl error ({$errno}):\n {$error_message}"; }     echo $response; 

changes:

$build_query = http_build_query($data);

$len = 'content-length: ' . strlen($build_query);

curl_setopt($ch, curlopt_postfields,$build_query)

remove url encode curlopt_url


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -