PHP Curl request with http authentication and POST -
i'm having trouble trying code running. i'm trying use curl post , http authentication i'm unable work.
i'm using following code:
public function index(){ $call = $this->call("url_to_call", $this->getcredentials(), $this->getjson()); } private function getcredentials(){ return "api_key_here"; } private function getjson(){ return $json; } private function call($page, $credentials, $post){ $url = "url_to_call"; $page = "/shipments"; $headers = array( "content-type: application/vnd.shipment+json;charset=utf-8", "authorization: basic :" . base64_encode($credentials) ); $ch = curl_init(); curl_setopt($ch, curlopt_url,$url); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_timeout, 60); curl_setopt($ch, curlopt_httpheader, $headers); // apply post our curl call curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_postfields, $post); $data = curl_exec($ch); if (curl_errno($ch)) { print "error: " . curl_error($ch); } else { // show me result var_dump($data); curl_close($ch); } }
the response i'm getting is:
{"errors":[{"code":3001}],"message":"permission denied. (insertshipment)"}
i expecting list of shipments. doing wrong here?
looking @ code, stipulate url in variable stipulate exact page, when set url curl, merely using url variable opposed url + page variables.
Comments
Post a Comment