【发布时间】:2019-05-04 07:27:35
【问题描述】:
我正在开发运输 API,它提供有关邮递员的数据,但是当我编码时,它提供的数据流无法打开:
HTTP 请求失败! HTTP/1.1 401 未经授权。
谢谢大家帮忙
我通过文件获取内容在标题中传递值并在正文中传递参数
$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);
【问题讨论】:
-
401 UNAUTHORIZED错误可能意味着您的授权标头有问题。我认为authorization:中的Token这个词看起来不合适。但这只是一个疯狂的猜测。旁注:在这里发布你的代币是否明智?
标签: php api codeigniter file-get-contents