1
我正在將wordpress網站與外部API集成。我有一個表單發佈到我的服務器,我在我的服務器上調用了一個對外部API進行wp_remote_get調用的函數。將pdf從wp_remote_get發送到瀏覽器
外部API返回一個PDF,與像頭:
[date] => Fri, 18 Aug 2017 15:59:19 GMT
[x-powered-by] => Servlet/3.0
[cache-control] => no-cache
[content-type] => application/pdf;charset=utf-8
[content-language] => en-US
和響應身體是PDF討厭的字符串格式,這似乎是一個良好的開端。
如何將此PDF傳遞給用戶的瀏覽器? 即
$response = wp_remote_get($url, array (//stuff the request needs));
if (is_wp_error ($response)) {
$error_message = $response->get_error_message();
echo "Something went wrong: $error_message";
} else {
//What here?
}
我得先打我的服務器,不能直接發帖的形式向外部API。