我正在使用 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 应用程序调用它时,结果表明没有正确发送标头,这导致了上述错误。任何人都会知道为什么没有发送标题?