I am working on shipping API and it giving data on postman but when I codes it gives failed to open stream:
HTTP request failed! HTTP/1.1 401 UNAUTHORIZED.
Thanks anybody can help
I have pass values in header and pass parameter in body by file get contents
$postdata = http_build_query(
array(
'phone' => '1111111111',
'city' => 'Kota',
'name' => 'ABC',
'pin' => '324005',
'address' => 'address',
'country' => 'India',
'contact_person' => 'name',
'email' => 'a@gmail.com',
'registered_name' => 'registered_name',
'return_address' => 'return_address',
'return_pin' => '110017',
'return_city' => 'delhi',
'return_state' => 'delhi',
'return_country' => 'india',
)
);
$opts = array('https'=>
array (
'method' => 'POST',
'header'=>array(
'authorization: Token', // removed token for protection
'Content-type: application/xwww-form-urlencoded',
'content-type: application/json',
),
'content-Type' =>$postdata,
)
);
$url="https://staging-express.delhivery.com/api/backend/clientwarehouse/create/";
$context=stream_context_create($opts);
$result=file_get_contents($url,false,$context);
I don't believe this is valid:
$opts = array('https'=>
Even for an https request, it should be:
$opts = array('http'=>
Also, if I read this right, I think your:
'content-Type' =>$postdata,
should be:
'content' =>$postdata,