cURL GET响应难以理解

时间:2018-06-13 19:40:51

标签: php curl walmart-api

尝试使用walmart api获取项目报告csv文件但没有运气,反而得到这个不可读的响应。需要帮忙。我怎样才能做到这一点?

以下是回复的屏幕截图:

cURL GET Response

这是我的代码:

$walmart_consumer_id = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
$walmart_channel_type = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
$dtd = date("Y_m_d");

$request_type = "GET";

$url = "https://marketplace.walmartapis.com/v2/getReport?type=item";

// We need a timestamp to generate the signature and to send as part of the header
$timestamp = round(microtime(true) * 1000);

$signature = getClientSignature($url, $request_type, $timestamp);

$headers = array();
$headers[] = "Accept: application/xml";
$headers[] = "WM_SVC.NAME: Walmart Marketplace";
$headers[] = "WM_CONSUMER.ID: ".$walmart_consumer_id;
$headers[] = "WM_SEC.TIMESTAMP: ".$timestamp;
$headers[] = "WM_SEC.AUTH_SIGNATURE: ".$signature;
$headers[] = "WM_QOS.CORRELATION_ID: ".mt_rand();
$headers[] = "WM_CONSUMER.CHANNEL.TYPE: " .$walmart_channel_type;
$headers[] = "Content-type: text/";

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request_type);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

var_dump($result);

1 个答案:

答案 0 :(得分:0)

看起来响应是ZIP格式;注意结果中的前两个字符是“PK” - 这是神奇的说它是zip格式。可能是卷曲解码ZIP格式的选项。