无法让Guzzle为原始图像数据强制内容类型

时间:2016-12-16 15:47:04

标签: php curl guzzle

我使用Guzzle 6并且在从REST端点获取图像数据时出现问题。

$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 个答案:

答案 0 :(得分:1)

您无法强制响应的内容类型。

您使用的Content-Type标题是请求的内容类型,而不是响应

如果您使用的端点(API?)使您能够控制响应,它可能将基于您正在使用的URL,但它不能告诉Guzzle更改。

相关问题