'file_get_contents(): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request

I am getting the error Warning: file_get_contents(https://partner.uat.shopeemobile.com/api/v1/item/categories/get): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in C:\xampp\htdocs\addproduct.php on line 43

<?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);
?>


Solution 1:[1]

In the $options array you have 'method' and you are passing in invalid stuff, method should be just a valid HTTP request method like POST or GET etc.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Moses Schwartz