Unable to POST xml string to webservice with PHP
-
29-05-2021 - |
题
I've been working on this for days and I can't seem to get it to work. Does anyone see a problem with the code below?
The result is nothing. I get no response from the service whatsoever. I've confirmed that the webservice, written in .Net, can accept and xml string, I've matched their schema, etc. But I get no response back.
I should also mention that I'm new to using web services with php but have done this in .Net countless times.
Additionally, is there a way to test the webservice .asmx to view any type of error output in php just to see if it's even working on the server side?
<?php
$url = 'https://someurl/someservice.asmx';
$xml = '<?xml version="1.0" encoding="utf-8" ?>
<query>
<version>1.0</version>
<login>userName</login>
<password>password</password>
<keyword>cancer</keyword>
</query>';
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_HEADER, true);
curl_setopt($c, CURLOPT_HTTPHEADER, array("application/x-www-form-urlencoded", "Content-length: ".strlen($xml)));
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, 'xmlInput='.urlencode($xml));
curl_setopt($c, CURLOPT_TIMEOUT, (int)30);
$xmlResponse = curl_exec($c);
curl_close ($c);
echo 'Output :: '.$xmlResponse;
?>
解决方案
Have you tried adding the following to your request?
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, false);
其他提示
try without
<?xml version="1.0" encoding="utf-8" ?>
or whrite
<?xml version=\"1.0\" encoding=\"utf-8\" ?>
不隶属于 StackOverflow