惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
B
Blog
Stack Overflow Blog
Stack Overflow Blog
量子位
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Tailwind CSS Blog
MongoDB | Blog
MongoDB | Blog
小众软件
小众软件
博客园 - 三生石上(FineUI控件)
Recent Announcements
Recent Announcements
U
Unit 42
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
腾讯CDC
D
DataBreaches.Net
Microsoft Azure Blog
Microsoft Azure Blog
G
Google Developers Blog
M
MIT News - Artificial intelligence
P
Proofpoint News Feed
罗磊的独立博客
L
LangChain Blog
V
Visual Studio Blog
雷峰网
雷峰网
aimingoo的专栏
aimingoo的专栏
宝玉的分享
宝玉的分享

zodream梦想开源/个人编程日记

文件解析笔记-zodream梦想开源/个人编程日记 密码本开发笔记之读写与保存-zodream梦想开源/个人编程日记 SkiaSharp 把 pixel byte[] 转成 SKBitmap-zodream梦想开源/个人编程日记 nas 使用 Docker 安装 gogs-zodream梦想开源/个人编程日记 复制 android 手机中的文件到电脑-zodream梦想开源/个人编程日记 周报:寻找优质的周刊-zodream梦想开源/个人编程日记 开发日志:对Markdown的代码块新增引用来源支持-zodream梦想开源/个人编程日记 周报:怎么写技术类的教程文章-zodream梦想开源/个人编程日记 css display:flex 布局尺寸超出问题-zodream梦想开源/个人编程日记 周报:SEO优化的思考-zodream梦想开源/个人编程日记 Edge 浏览器不适用 Edge Image Viewer 打开图片 -zodream梦想开源/个人编程日记 SEO 学习笔记(一) 内容来源-zodream梦想开源/个人编程日记 PHP 实现双因素身份认证(2FA)-zodream梦想开源/个人编程日记 WPF MVVM 获取List 多选数据-zodream梦想开源/个人编程日记 Burp Suite 抓包-zodream梦想开源/个人编程日记 使用 indexnow 注意事项-zodream梦想开源/个人编程日记 Godot 使用字体图标 例如: Iconfont、FontAwesome-zodream梦想开源/个人编程日记 angular 15 对指定页面进行访问限制-zodream梦想开源/个人编程日记 CSS 使用 column-count 实现瀑布流出现内容分割的解决办法-zodream梦想开源/个人编程日记 input 确认按键事件在手机端不生效-zodream梦想开源/个人编程日记 C# 使用socket 进行通讯-zodream梦想开源/个人编程日记 Maui开发中Windows应用开启管理员权限-zodream梦想开源/个人编程日记 Maui 中自定义控件-zodream梦想开源/个人编程日记 angular 14 使用 ng-template 实现tree 结构显示-zodream梦想开源/个人编程日记 c# 动态安装和卸载dll-zodream梦想开源/个人编程日记 慎用 CompositionTarget.Rendering-zodream梦想开源/个人编程日记 c# 重写 c++ 程序笔记:数据初始化-zodream梦想开源/个人编程日记 源码编译 aseprite-zodream梦想开源/个人编程日记 记录一下字符串分隔split各语言之间的不同-zodream梦想开源/个人编程日记 c# Gzip解码无头内容-zodream梦想开源/个人编程日记
php soap 访问.net Web 服务-zodream梦想开源/个人编程日记
zodream · 2019-12-04 · via zodream梦想开源/个人编程日记

php soap 访问.net Web 服务

一开始使用soap 连接是报 Couldn't load from 'xxxx' : Premature end of data in tag html line

发现是参数设的不对,SoapClient第一个参数使用的是正式请求网址,SoapHeader 第一个参数设的namespace,不能使用默认的 http://tempuri.org/, 不然 headerbodynamespace 相同 ,header 就不会生成加入到xml请求内容中。

__soapCall 的第二个参数传递的是方法的所有参数,类似于 ...args, 所以必须用数组包起来 [参数1, 参数2, ...]

$client = new SoapClient('http://zodream.cn/PosWebService.asmx?WSDL', ['trace' => 1, 'exception' => 0]);
$header = new SoapHeader('http://microsoft.com/webservices/', 'SoapHeader', [
    'User' => 'zodream',
    'Password' => 'zodream'
]);
$res = $client->__soapCall($path, [$data], null, $header);

123456

但是老是报错 Could not connect to host

按照搜到的方法改了 php.ini

soap.wsdl_cache_enabled=0
soap.wsdl_cache_ttl=0
soap.wsdl_cache_limit = 0

123

发现还不行,再次修改代码

$client = new SoapClient('http://zodream.cn/PosWebService.asmx?WSDL', ['trace' => 1, 'exception' => 0]);
$client->soap_defencoding = 'utf-8';  
$client->decode_utf8 = false;   
$client->xml_encoding = 'utf-8'; 
$header = new SoapHeader('http://microsoft.com/webservices/', 'SoapHeader', [
    'User' => 'zodream',
    'Password' => 'zodream'
]);
$res = $client->__soapCall($path, [$data], null, $header);

123456789

还是不行,有尝试过使用 fsockopen 发现连接直接超时

然后用 postman 测试发现需要加上 Content-Type: text/xml;charset=utf-8 服务端才能接收,否则响应 服务器无法为请求提供服务,因为不支持该媒体类型。, 最后没办法只能修改请求方法

$client = new ZoClient('http://zodream.cn/PosWebService.asmx?WSDL', ['trace' => 1, 'exception' => 0]);
$client->soap_defencoding = 'utf-8';  
$client->decode_utf8 = false;   
$client->xml_encoding = 'utf-8'; 
$header = new SoapHeader('http://microsoft.com/webservices/', 'SoapHeader', [
    'User' => 'zodream',
    'Password' => 'zodream'
]);
$res = $client->__soapCall($path, [$data], null, $header);

class ZoClient extends SoapClient {
    public function __doRequest($request, $location, $action, $version, $one_way = 0) {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $location);
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_HTTPHEADER, [
            'Content-Type: text/xml;charset=utf-8',
            'SoapAction: '.$action
        ]);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
        $response = curl_exec($curl);
        curl_close($curl);
        return $response;
    }
}

123456789101112131415161718192021222324252627

虽然可以直接使用curl自己写,但拼接soapxml有点麻烦,转化响应也麻烦,直接使用soap插件就不麻烦了。

转载请保留原文链接: https://zodream.cn/blog/id/88.html