【问题标题】:not getting response from api post没有从 api post 得到响应
【发布时间】: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


【解决方案1】:

我不认为这是有效的:

$opts = array('https'=> 

即使是 https 请求,也应该是:

$opts = array('http'=> 

另外,如果我没看错的话,我认为你的:

'content-Type' =>$postdata,

应该是:

'content' =>$postdata,

【讨论】:

    猜你喜欢
    • 2016-01-09
    • 2019-01-23
    • 1970-01-01
    • 1970-01-01
    • 2020-02-09
    • 2017-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多