【问题标题】:Sending a custom header with ZEND_HTTP_CLIENT使用 ZEND_HTTP_CLIENT 发送自定义标头
【发布时间】:2015-09-21 08:34:36
【问题描述】:

如何发送带有ZEND_HTTP_CLIENT 的自定义标头。我正在尝试发送具有特定值的变量key,稍后我将检查其真实性

我试过了

       $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);

还有这个

  $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);

但它似乎不起作用。它说key 不是有效类型。 我想发送这样的自定义标头(类似于使用 Postman 客户端设置标头时发生的情况)。 这可能吗?

【问题讨论】:

  • 您应该知道使用不带X- 前缀的非标准标头是一种不好的做法。如果您对服务器的期望有任何控制权,我建议您使用X-Key 而不是仅使用Key,如 HTTP RFC 中所定义。
  • 实际上你不应该使用任何 X- 前缀,就像tools.ietf.org/html/rfc6648

标签: php zend-framework zend-http-client


【解决方案1】:

尝试添加这样的配置参数:

 $client = new Zend_Http_Client('http://localhost/v3/files/', array('strict' => false));

【讨论】:

    猜你喜欢
    • 2012-11-26
    • 2012-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-29
    • 2018-10-03
    • 1970-01-01
    相关资源
    最近更新 更多