SoapClient 设置自定义 HTTP Header

SoapClient set custom HTTP Header(SoapClient 设置自定义 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Uploading Image from android to PHP server(将图像从android上传到PHP服务器)
Sending file together with form data via ajax post(通过ajax post将文件与表单数据一起发送)
Laravel - validate file size when PHP max upload size limit is exceeded(Laravel - 超过 PHP 最大上传大小限制时验证文件大小)
How to upload file through Jquery/AJAX(如何通过 Jquery/AJAX 上传文件)
PHP: move_uploaded_file() failed to open stream: No such file or directory(PHP:move_uploaded_file() 无法打开流:没有那个文件或目录)
Creating a file progress bar in PHP(在 PHP 中创建文件进度条)