我被要求将以下Javascript函数转换为PHP函数。
我之前从未被要求做过这样的事情,所以一直在苦苦挣扎,可能有与SOAP / WebServices等有关的所有错误术语,所以我对任何困惑表示歉意。
var varValidationCode = "VALIDATIONCODE";
var Email = document.getElementById('Email').value;
//alert(Email);
$.ajax(
{
url: 'http://www.DOMAIN.com/FILE.asmx',
type: "POST",
data: "{Email:'" + Email + "',ValidationCode:'" + varValidationCode + "'}",
dataType: "json",
contentType: "application/json; charset=utf-8",
cache: false,
success: function(data) {
alert(data.d);
},
error: function() {
alert("FAIL");
}
});
//alert("Function Called Successfully");
}
我尝试创建一个curl函数来发布下面的值,这是我从stackoverflow上的另一篇文章得到的,但是我得到了错误 - " soap:ReceiverServer无法处理请求。 --->根级别的数据无效。第1行,第1位。"
// Here is the data we will be sending to the service
$data = array(
'Email' => 'TEST@TEST.COM',
'ValidationCode' => 'SOMEVALIDATIONCODE'
);
$curl = curl_init('http://www.DOMAINNAME.com/FILE.asmx');
curl_setopt($curl, CURLOPT_POST, 1); //Choosing the POST method
curl_setopt($curl, CURLOPT_URL, 'http://www.DOMAINNAME.com/FILE.asmx'); // Set the url path we want to call
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Make it so the data coming back is put into a string
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Insert the data
// Send the request
$result = curl_exec($curl);
// Free up the resources $curl is using
curl_close($curl);
echo $result;
我发布的文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="htt{://www.w3.org/2001/XMLSchema-instance" xmlns:xds="http://www.w3.org/2001/XMLSchema" xmlns:xds="http://www.w3.org/2001/05/soap-envelope">
<soap:Body>
<PaymentValidationInfo xmlns="http://tempuri.org/">
<Email>STRING</Email>
<ValidationCode>STRING</ValidationCode>
</PaymentValidationInfo>
<soap12:Body>
</soap12:Envelope>
我希望这一切都有道理。 任何帮助将非常感激。 此致
答案 0 :(得分:0)
我不确定人们是否有兴趣,但我设法通过以下工作了解如何获得我想要的工作。
$url = "http://www.domain.com/WebServices/CCPWebService.asmx/METHOD?";
$data = array(
'Email' => 'EMAIL',
'&ValidationCode' => '4946565',
);
foreach($data as $key=>$value) { $content .= $key.'='.$value; }
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
/* FOR DEBUG PURPOSES
if(!curl_errno($curl))
{
$info = curl_getinfo($curl);
echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'].'<br/><br/>';
echo "CURL ERROR NO : ".curl_errno($curl); //returns 7
echo "<br />CURL STATUS : ".curl_getinfo($curl, CURLINFO_HTTP_CODE); //returns 0
echo "<br />CURL ERROR : ".curl_error($curl); //returns "couldn't connect to host"
echo "<br />STRINGS POSTED: ";print_r($content);
echo "<br />CURL INFO : ";print_r($info);
}*/
curl_close($curl);
如果有人可以推荐任何添加/最佳实践,我们将不胜感激。 此致