Zend Http客户端 - 无效的内容类型错误
问题描述:
我收到一个无效的内容类型错误,发送到ApiGility API的POST请求。Zend Http客户端 - 无效的内容类型错误
阵列(大小= 4) '类型'=>串 'http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html'(长度= 54)
'标题'=>字符串 '不支持的媒体类型'(长度= 22) '状态'=> INT 415“细节” =>字符串“指定了无效的内容 - 类型” (长度= 30)
因此,这是告诉我,我在不正确的内容类型正在发送。
这里是我的代码:
$client = new Client(); //Zend/Http/Client
$client->setUri('http://example.com/api/transfer');
$client->setMethod('POST');
$client->setOptions(
[
'maxredirects' => 0,
'timeout' => 60
]
);
$client->setHeaders(['Accept' => 'application/json', 'Authorization' => 'Bearer 123453c112345c25256ff2dacb8ab212345ace91' ]);
$client->setParameterPost(
[
'total' => 1,
'code' => '0f08c43582f14686aabec4610b332629'
]
);
try {
$response = $client->send();
} catch (\Exception $e) {
throw new \Exception($e);
}
$responseObject = json_decode($response->getBody());
$hydrator = new \Zend\Stdlib\Hydrator\ObjectProperty;
$result = $hydrator->extract($responseObject);
die(var_dump($result));
我不能从手动摸出什么:http://framework.zend.com/manual/current/en/modules/zend.http.client.html或实际的客户端的代码,是在哪里设置的内容类型?
答
'Content-Type'
应该只是您用于$client->setHeaders()
的阵列中的另一个条目。但客户应该默认为'multipart/form-data'
。
你能做一个var_dump()
的$client->getRequest()->getHeaders()
?
谢谢 - 这让我超越了内容类型错误。 – HappyCoder