我的情况是
用Laravel发送请求应该是这样的
$res = Http::withHeaders([
'Content-Type' => 'application/json',
'Authorization' => $secret_key
])->post($api_url, [
"ordersn_list" => [$order_no],
"shopid" => $shop_id,
"partner_id" => $partner_id,
"timestamp" => $timestamp
]);但是Shopee不需要主体部分中的空间(不能以JSON格式发送)。我试过了
$res = Http::withHeaders([
'Content-Type' => 'application/json',
'Authorization' => $secret_key
])->post($api_url, $body_string);它不能工作,因为它必须是一个数组。返回错误Argument 2 passed to Illuminate\Http\Client\PendingRequest::post() must be of the type array, string given。
发布于 2020-09-06 15:28:22
试试这个:
$data = [
"ordersn_list" => [$order_no],
"shopid" => $shop_id,
"partner_id" => $partner_id,
"timestamp" => $timestamp
];
$res = Http
::asJson()
->withHeaders([
'Authorization' => $secret_key
])
->post($api_url, $data);或者:
$data = [
"ordersn_list" => [$order_no],
"shopid" => $shop_id,
"partner_id" => $partner_id,
"timestamp" => $timestamp
];
$res = Http
::withHeaders([
'Authorization' => $secret_key
])
->withBody(json_encode($data), 'application/json')
->post($api_url);https://stackoverflow.com/questions/63765635
复制相似问题