file_get_contents():无法打开流:HTTP请求失败! HTTP / 1.1 400错误请求

时间:2019-08-22 01:19:07

标签: php api http

我收到错误警告:file_get_contents(https://partner.uat.shopeemobile.com/api/v1/item/categories/get):无法打开流:HTTP请求失败! C:\ xampp \ htdocs \ addproduct.php中第43行的HTTP / 1.1 400错误请求

<?php
    $api_authorization_base_url = "https://partner.shopeemobile.com/api/v1/shop/auth_partner";
    $redirect_url = "https://www.google.com";

    $partner_id = 840565;
    $shopid =  209194;
    $key = "aca9b2236136e7aeb8be2b11197a181cd6bc672cbc641f8fe41d0850b7b7f63a";

    $token_base_string = $key . $redirect_url;
    $token = hash('sha256', $token_base_string);
    $data = array(
        'id' => $partner_id,
        'token' => $token,
        'redirect' => $redirect_url
    );

    $api_authorization_url = $api_authorization_base_url . "?" . json_encode($data);
    // echo $api_authorization_url . "\n";
    $get_order_by_status_url = "https://partner.uat.shopeemobile.com/api/v1/item/categories/get";

    $data = array(
        'partner_id' => $partner_id,
        'shopid' => $shopid,
        'timestamp' => time(),
        "language" => "en"     

    );
    $sig_base_string = $get_order_by_status_url . " |" . json_encode($data);
    $sig = hash_hmac('sha256', $sig_base_string, $key);
    $header = [
        'Authorization' => $sig
    ];
    $options = array(
        'http' => array(
          'header'  => "Content-type: application/json\r\n Authorization: " . $sig,
          'method'  => 'POST /api/v1/item/categories/get HTTP/1.1',
          'content' => json_encode($data)
        ),
      );

    $context  = stream_context_create($options);
    // print_r($sig_base_string);
    $result = file_get_contents($get_order_by_status_url, false, $context);
     print_r($result);
?>

1 个答案:

答案 0 :(得分:0)

$options数组中,您有'method',并且您传递的是无效内容,方法应该只是有效的HTTP请求方法,例如POSTGET等。< / p>