Zend\Http\Request と Zend\Http\Client を使用して次のリクエストを作成しています
//Creating request and client objects
$request = new Request();
$client = new Client();
//Preparing Request Object
$request->setMethod('POST');
$request->setUri('https://my.api.address.com/apiendpointurl1234');
$request->getHeaders()->addHeaders(array(
'cache-control' => 'no-cache',
'content-type' => 'application/json',
'client_secret' => 'asdfasdfasdfasdfasdf',
'client_id' => 'asdfasdfasdfasdfasdf',
'accept' => 'application/json',
'authorization' => 'Basic MTIzNDoxMjM0',
));
$request->getPost()->set(json_encode(array(
'student_id' => '123456',
'short_description' => 'this is short description',
'description' => 'this is detailed description of the question',
)));
//Sending Request
$response = $client->send($request);
var_dump( $response->getBody() );
ただし、応答には次のエラーが表示されます。
"エラー": "ヘッダー: client_id が必要です"
Postman 経由で API を突くと、問題なく動作します。しかし、PHP アプリケーションから呼び出すと、ヘッダーが正しく送信されていないことがわかり、上記のエラーが発生します。ヘッダーが送信されない理由を誰でも知っていますか?