【问题标题】:PHP CURL Soap Request Print ResponsePHP CURL Soap 请求打印响应
【发布时间】:2013-04-11 22:03:38
【问题描述】:

您好,我正在尝试向 powerpay.biz 发送 Soap 请求但没有得到响应,而且当我使用我的测试 url 时

https://gkicmerchants.com/admin/classes/soap-request.xml

我收到这个错误

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Start tag expected, '<' not found in /home/content/g/k/i/gkic1848/html/admin/classes/submit_applicant.class.php on line 299

这是我的代码:

$username = 'user';
$password = 'password';
$credentials = $username.":".$password; 
$url = "http://gkicmerchants.com/admin/classes/soap-server.php";

$soap_request = '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
            <soap:Body>
            ....
            </soap:Body>
            </soap:Envelope>';

$header = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: '".$url."'",
"Content-length: ".strlen($soap_request),
);


$curl = curl_init(); 

curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ) ; 
curl_setopt($curl, CURLOPT_USERPWD, $credentials); 
curl_setopt($curl, CURLOPT_SSLVERSION,3); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); 
curl_setopt($curl, CURLOPT_HEADER, true); 
curl_setopt($curl, CURLOPT_POST, 1); 
curl_setopt($curl, CURLOPT_POSTFIELDS, $soap_request );
curl_setopt($curl, CURLOPT_HTTPHEADER,     $header);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); 
curl_setopt($curl, CURLOPT_URL, $url); 

// perform the request

$xml_result = curl_exec($curl);
// check for errors
if ($xml_result === false) {
$error_occurred = true;
}
else {

    $xml = new SimpleXMLElement($xml_result);

    print_r($xml);
}

curl_setopt 选项有问题吗?

【问题讨论】:

  • 错误消息暗示您收到的响应格式不正确 - 您是否尝试回显 $xml_result 以查看实际返回的内容?
  • 当我回显我得到的结果时:HTTP/1.1 100 Continue HTTP/1.1 200 OK 日期:星期四,2013 年 4 月 18 日 17:06:27 GMT 服务器:Apache 内容长度:0 内容类型: 文本/html
  • 那么问题是您没有从服务器收到响应 - 您可以从服务器获取任何信息以查看那里发生了什么吗?
  • 他们说他们没有看到我的任何新请求。

标签: php soap curl xmlhttprequest


【解决方案1】:

不要在输出中包含响应标头。删除这一行:

curl_setopt($curl, CURLOPT_HEADER, true); 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-09
    • 2019-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-03
    • 2015-01-26
    相关资源
    最近更新 更多