Ganesh Babu
Ganesh Babu

Reputation: 3670

Zend Header issue

I tried setting custom headers in Zend request. I am getting the below error:

 Argument 1 passed to Zend\\Http\\AbstractMessage::setHeaders() must be an instance of Zend\\Http\\Headers, array given

Below is my code sample:

<?php
$request = new Request();
$request->setContent($parameters);
$request->setMethod(Request::METHOD_POST);
$request->setHeaders(array("Authorization: MyAuth $authId"));
$request->setUri($url);

I also tried giving the headers in string format. But still I am facing the same error. Can anyone find out what issue is made here in setting headers?

Upvotes: 0

Views: 158

Answers (2)

sozkul
sozkul

Reputation: 675

$request->setHeaders() wants an instance of Zend\Http\Headers() as parameters. So you can create an instance

$headers = new Zend\Http\Headers();
$headers->addHeaders("Authorization","MyAuth ".$authId);

or

$headers = Zend\Http\Headers::fromString($headerString);

Check this

Upvotes: 0

KiwiJuicer
KiwiJuicer

Reputation: 1982

the error says it all, the setHeaders is expecting an object of the type \Zend\HTTP\Headers.

Try to create the object first:

$headers = new \Zend\Http\Headers();
$headers->addHeaderLine('[YOUR HEADER LINE]');

$request->setHeaders($headers);

Upvotes: 1

Related Questions