我正在执行联邦快递ETD API。我使用的代码在这里。它的给予我错误。你会检查这个问题是什么/是
$url = "https://documentapitest.prod.fedex.com/sandbox/documents/v1/etds/upload";
$access_token = $authToken;
$file = fopen("fg_SO-000022647-WAR-2.pdf", "rb");
$textData = fread($file, filesize("g_SO-000022647-WAR-2.pdf"));
fclose($file);
$headers = array(
"Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
"x-customer-transaction-id: 12XXXXXX",
"Authorization: Bearer ".$access_token
);
$data = array(
"document" => '{
"workflowName":"ETDPreshipment","name":"g_SO-000022647-WAR-2.pdf","contentType":"text/plain",
"meta":{"shipDocumentType":"COMMERCIAL_INVOICE","originCountryCode":"DK","destinationCountryCode":"BE"}}'
);
$files = array(
"attachment" => array("g_SO-000022647-WAR-2.pdf", $textData, "text/plain")
);
$postData = array(
'data' => json_encode($data),
'attachment' => new CURLFile('C:\xampp\htdocs\test\g_SO-000022647-WAR-2.pdf', 'text/plain', 'application/pdf')
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$response = curl_exec($ch);
if ($response === false) {
echo 'Curl error: ' . curl_error($ch);
print_r(curl_error($ch));
}
curl_close($ch);
print_r($response);
字符串
它给予这个错误:
error
:
"Bad Request"
message
:
"Required request part 'document' is not present"
path
:
"/document/v1/etds/upload"
型
1条答案
按热度按时间6uxekuva1#
使用Client()代替cURL
字符串