2

How can I send a custom header with the ZEND_HTTP_CLIENT. I am trying to send a variable key with a certain value, that I will check later for authenticity

I've tried this

       $client = new Zend_Http_Client('http://localhost/v3/files/');
       $client->setHeaders('Content-type','multipart/form-data');
       $client->setHeaders('key','XXXxXXXXXXXXXXXXXX');

       $client->setParameterPost('document_id', $id);
       $client->setParameterPost('type_id', $docType['type']);
       $client->setParameterPost('file', $form->file);
       $response = $client->request(Zend_Http_Client::POST);

and this

  $client = new Zend_Http_Client('http://localhost/v3/files/');
   $client->setHeaders(array(
      'Content-type','multipart/form-data',
      'key','XXXxXXXXXXXXXXXXXX'));

       $client->setParameterPost('document_id', $id);
       $client->setParameterPost('type_id', $docType['type']);
       $client->setParameterPost('file', $form->file);
       $response = $client->request(Zend_Http_Client::POST);

but it doesnt seem to work. It says key is not a valid type. I want to send a custom header like this (similar to what happens when you set headers with the Postman client). Is this possible?

Vrashabh Irde
  • 14,129
  • 6
  • 51
  • 103
  • You should know it is a bad practice to use non-standard headers without an `X-` prefix. If you have any control over what the server expects, I would suggest using `X-Key` instead of just `Key`, as is defined in the HTTP RFC. – shevron Sep 21 '15 at 20:25
  • Actually you should not use any X- prefixes, as per https://tools.ietf.org/html/rfc6648 – naderman Mar 30 '16 at 14:02

1 Answers1

1

Try with add a config param like this:

 $client = new Zend_Http_Client('http://localhost/v3/files/', array('strict' => false));
doydoy44
  • 5,720
  • 4
  • 29
  • 45