【问题标题】:cURL GET response unreadable [duplicate]cURL GET响应不可读[重复]
【发布时间】:2018-06-13 19:40:50
【问题描述】:

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

这是回复的截图:

这是我的代码:

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

【问题讨论】:

  • 你能把回复的$headers也发一下吗?

标签: php curl walmart-api


【解决方案1】:

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

【讨论】:

  • 如何读取 zip 中的 csv 文件以便我可以处理该数据?
  • 对不起;我对curl和php不够熟悉;当我在十六进制转储中看到一个 ZIP 文件时,我只知道一个 ZIP 文件,并且知道大多数网站以 zip 格式交付其内容以节省空间和网络时间。
猜你喜欢
  • 1970-01-01
  • 2013-03-30
  • 2013-01-08
  • 1970-01-01
  • 2021-02-12
  • 2017-06-18
  • 1970-01-01
  • 2015-06-20
  • 1970-01-01
相关资源
最近更新 更多