Execute SOAP using cURL(使用 cURL 执行 SOAP)
问题描述
我正在尝试使用 cURL 执行 SOAP 函数(因为我在使用 SoapClient() 时遇到错误).
I am trying to execute an SOAP-function using cURL (because I get an error using the SoapClient().
这是我的代码(已完成一半)
This is my code (that is halfway working)
$credentials = "username:pass"; 
$url = "https://url/folder/sample.wsdl"; 
$page = "/folder"; 
$headers = array( 
    "POST ".$page." HTTP/1.0", 
    "Content-type: text/xml;charset="utf-8"", 
    "Accept: text/xml", 
    "Cache-Control: no-cache", 
    "Pragma: no-cache", 
    "SOAPAction: "customerSearch"", 
    "Authorization: Basic " . base64_encode($credentials) 
); 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL,$url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch, CURLOPT_USERAGENT, $defined_vars['HTTP_USER_AGENT']); 
$data = curl_exec($ch); 
问题在于没有执行 SOAP 操作.而且我还需要将参数传递给操作.这甚至可能吗?
The problem is that the SOAP-action is not being performed. And I also need to pass arguments to the action. Is this even possible?
推荐答案
您需要指定 POST 的 cURL 选项,并设置请求的正文 - 如果您不发送正文,则 POST 请求没有意义(更重要的是,它不是 SOAP).构建一个完整的 HTTP 请求标头不会削减它.
You need to specify the cURL options to POST, and set the body of the request - if your not sending a body, there's no point in a POST request (and more importantly, it isn't SOAP). Building a complete HTTP request header just won't cut it.
$credentials = "username:pass"; 
$url = "https://url/folder/sample.wsdl";
$body = ''; /// Your SOAP XML needs to be in this variable
$headers = array( 
    'Content-Type: text/xml; charset="utf-8"', 
    'Content-Length: '.strlen($body), 
    'Accept: text/xml', 
    'Cache-Control: no-cache', 
    'Pragma: no-cache', 
    'SOAPAction: "customerSearch"'
); 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_USERAGENT, $defined_vars['HTTP_USER_AGENT']);
// Stuff I have added
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $body); 
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $credentials);
$data = curl_exec($ch); 
                        这篇关于使用 cURL 执行 SOAP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 cURL 执行 SOAP
				
        
 
            
        - 如何定位 php.ini 文件 (xampp) 2022-01-01
 - SoapClient 设置自定义 HTTP Header 2021-01-01
 - 没有作曲家的 PSR4 自动加载 2022-01-01
 - Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
 - PHP Count 布尔数组中真值的数量 2021-01-01
 - Laravel 仓库 2022-01-01
 - 带有通配符的 Laravel 验证器 2021-01-01
 - Mod使用GET变量将子域重写为PHP 2021-01-01
 - 正确分离 PHP 中的逻辑/样式 2021-01-01
 - 从 PHP 中的输入表单获取日期 2022-01-01
 
				
				
				
				