2016-12-16 23 views
1

我正在使用Guzzle 6並且在從REST端點獲取圖像數據時遇到問題。無法使用Guzzle強制原始圖像數據的內容類型

$client = new Client(['base_uri' => $base_uri]); 
$type = 'POST'; //..or 'GET'...doesn't make a difference 
$url = //..the endpoint where the image is served from 
$headers['Content-Type'] = 'text/xml; charset=x-user-defined'; 
$response = $client->request($type, $url, ['headers'=>$headers, 'decode_content' => false]); 

我的要求,迫使MIME類型被忽略,返回的內容類型總是"image/jpeg",並且數據被改寫的,所以我不能簡單地把它粘成一個html標籤"<img src=... />"

回答

1

您不能強制響應的內容類型。

您使用的Content-Type頭是內容類型爲請求而不是響應

如果您使用的端點(API?)爲您提供了控制響應的功能,它可能將基於您使用的URL,但它不是您可以告訴Guzzle更改的內容。

+0

謝謝...我終於意識到,我可以做任何我想要的數據從流中返回的數據;在這種情況下,如果我將它編碼到base64並在其前面放置正確的提示:'data:image/jpeg; base64,' - html''標記正常工作。 –

+0

是的,那正確:) – Dekel

相關問題