如何在php的SoapClient中设置和禁用标头?

k0pernikus

SoapClient发送HTTP标头:

POST / HTTP/1.1
Accept: */*
Accept-Encoding: deflate, gzip
SOAPAction: ""
Content-Type: text/xml; charset=utf-8
Content-Length: 2085
Expect: 100-continue

HTTP/1.1 100 Continue

我想禁用Expect: 100-continue我怎样才能做到这一点?

我发现我应该能够通过以下方式设置自定义标头:

class SoapClient extends \SoapClient implements HttpClientInterface

    public function __construct($pathToWSDL, array $options, LoggerInterface $logger){
        ...
        $headers = [
            'stream_context' => stream_context_create(
                [
                    'http' => [
                        'header' => 'SomeCustomHeader: value',
                    ],
                ]
            ),
        ];
        parent::__construct($pathToWSDL, array_merge($options, $headers));
 }

但这不起作用。

如何设置自定义标头并禁用某些标头?

我也没有使用本地php,但是使用了HipHop VM 3.12.1(相对)。

利斯

HTTP上下文选项指示该header选项可以是字符串或字符串数组,并且将覆盖其他给定的选项。如果要使用带有多个选项的单个字符串,请使用回车符和换行符(\r\n)进行分隔,如第一个stream_context_create示例所示。

因此,构造应为:

'stream_context' => stream_context_create(
    [
        'http' => [
            'header' => "SomeCustomHeader: value\r\n".
                        "Expect: \r\n",
        ],
    ]
),

或者:

'stream_context' => stream_context_create(
    [
        'http' => [
            'header' => [
                'SomeCustomHeader: value',
                'Expect: ',
            ],
        ],
    ]
),

但是,在您的情况下,最有可能的原因是您使用的HHVM的版本-这是HHVM的错误,在3.15.0中似乎没有修复,因此您可能想要尝试升级HHVM并重试。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章