【发布时间】:2015-10-13 11:31:47
【问题描述】:
我在向 ApiGility API 发出 POST 请求时收到无效的内容类型错误。
array (size=4) 'type' => 字符串 'http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html' (长度=54)
'title' => string 'Unsupported Media Type' (length=22) 'status' => int 415 'detail' => string '指定的内容类型无效' (长度=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 或实际的客户端代码,在哪里设置内容类型?
【问题讨论】:
标签: php zend-framework laminas-api-tools