SoapClient set custom HTTP Header(SoapClient 设置自定义 HTTP Header)
问题描述
我正在编写一个基于 PHP 的 SOAP 客户端应用程序,该应用程序使用 PHP5 原生的 SOAP 库.我需要发送一个 HTTP cookie 和一个额外的 HTTP 标头作为请求的一部分.cookie部分没问题:
I am doing some work writing a PHP-based SOAP client application that uses the SOAP libraries native to PHP5. I need to send a an HTTP cookie and an additional HTTP header as part of the request. The cookie part is no problem:
代码:
$client = new SoapClient($webServiceURI, array("exceptions" => 0, "trace" => 1, "encoding" => $phpInternalEncoding));
$client->__setCookie($kkey, $vvalue);
我的问题是 HTTP 标头.我希望会有一个名为
My problem is the HTTP header. I was hoping there would have been a function named
__setHeader
或
__setHttpHeader
在 SOAP 库中.但没有这样的运气.
in the SOAP libraries. But no such luck.
有其他人处理过这个吗?有解决方法吗?使用不同的 SOAP 库会更容易吗?谢谢.
Anyone else dealt with this? Is there a workaround? Would a different SOAP library be easier to work with? Thanks.
<子>(我在这里发现了这个悬而未决的问题 http://www.phpfreaks.com/forums/index.php?topic=125387.0,我复制了 b/c 我有同样的问题)
(I found this unanswerd question here http://www.phpfreaks.com/forums/index.php?topic=125387.0, I copied it b/c i've the same issue)
推荐答案
尝试为 soap 客户端设置流上下文:
Try setting a stream context for the soap client:
$client = new SoapClient($webServiceURI, array(
"exceptions" => 0,
"trace" => 1,
"encoding" => $phpInternalEncoding,
'stream_context' => stream_context_create(array(
'http' => array(
'header' => 'SomeCustomHeader: value'
),
)),
));
这篇关于SoapClient 设置自定义 HTTP Header的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SoapClient 设置自定义 HTTP Header


基础教程推荐
- 超薄框架REST服务两次获得输出 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01