我一直在寻找使用 jQuery/AJAX 通过 SOAP 执行表单(发布)请求的方法。
我找到了以下针对具有 ColdFusion 背景的 jQuery/AJAX SOAP 请求的解决方案。
Posting XML SOAP Requests With jQuery
有人知道如何用 PHP 实现吗?
请注意:
- 需要ssl连接
- 将需要 soap 身份验证(用户和密码)。
非常感谢任何帮助/建议。
最佳答案
我知道这是旧的......但我遇到了这个确切的问题(我在他拥有的链接上使用了代理,并且在工作中迁移到新系统时我需要一个 php 中的代理。)
如果有人感兴趣,我将他们的 coldfusion 代理翻译成近似的 php 等效项(没有错误检查,但 jquery ajax 调用是相同的,除了 php 文件)
<?php
$action = $_SERVER['HTTP_SOAPACTION'];
$target = $_SERVER['HTTP_SOAPTARGET'];
$soap_body = file_get_contents('php://input');
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: ".$action,
"Content-length: ".strlen($soap_body),
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $target);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $soap_body);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);
echo($response);
?>
这里又是一个链接,可以查看调用此代理所需的 html 和 javascript/jquery。 http://www.bennadel.com/blog/1853-Posting-XML-SOAP-Requests-With-jQuery.htm
关于PHP/jQuery/AJAX + 带身份验证的 POST SOAP 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7109610/