PHP/jQuery/AJAX + 带身份验证的 POST SOAP 请求

标签 php soap wsdl

我一直在寻找使用 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/

相关文章:

php - 使用 php mysql ajax 进行实时搜索

java - 轴故障 : Transport error: 415 Error in AXIS2 client(JAVA)

java - 生成额外类的 WSDL 到 Java 代码方法

php - 必填字段错误检查不起作用

php - 学说查询生成器 : how to do a query with inner joins conditions

java - 有哪些不同的框架可用于 SOAP

Ruby 和 SOAP 创建 Web 服务代理和命名空间

c# - 使 Visual Studios "Add Service Reference"功能使用现有类

node.js - 如何在 node.js 中使用 wcf?

php - 无法使用 Jquery.post() 发布 JSON 对象