2 回答

TA貢獻(xiàn)1788條經(jīng)驗(yàn) 獲得超4個(gè)贊
你解決問題了嗎?下面的簡(jiǎn)單代碼對(duì)我有用
$fp = fopen('/your path where you store the zip file/'.$filename, 'w+');
if ($fp == FALSE){
print "File not opened<br>";
exit;
}
fwrite($fp, $response);
fclose($fp);
$response是 API 響應(yīng)的正文,它將是 $filename從標(biāo)頭中獲取的不可讀格式的 zip 文件名。

TA貢獻(xiàn)1735條經(jīng)驗(yàn) 獲得超5個(gè)贊
似乎 Json Encoded 并且您必須在 php 腳本中使用 json 對(duì)其進(jìn)行解碼,因此: json_decode(string,array) string = 您收集的編碼響應(yīng)。array = True 如果你想要結(jié)果數(shù)據(jù)的數(shù)組。
2- 使用 header('Content-Type: application/json') (此標(biāo)頭在發(fā)送或接收響應(yīng)之前最有用)
3 -錯(cuò)誤處理:json_last_error() json_last_error_msg()
try {
$header = $resultInfo->getHeader('Content-Disposition');
if (!empty($header)) {
if (strpos($header, 'filename') !== false) {
$filename = substr($header, strpos($header, 'filename'));
$str = explode('=', $filename);
$body = $resultInfo->getBody();
$fp = fopen(storage_path("csv/{$str[1]}"), 'w');
##uncomment below line if response not valid may help you.
# header('Content-Type: application/json');
$dbody = json_decode($body,true);
fwrite($fp, $dbody);
fclose($fp);
}
}
} catch (\Exception $e) {
echo $e->getMessage();
}
希望能有所幫助
- 2 回答
- 0 關(guān)注
- 133 瀏覽
添加回答
舉報(bào)