dqol6556 2017-01-24 19:24
浏览 41

通过PHP + AJAX进行Soap请求

I need to make a Soap Request via PHP. To start from the beginning.. I have a html web page with a form and a button(not a submit btn). When the button is clicked an AJAX should POST two input values from the form to 'soap.php'. After that a Soap Request should be send to Web Service via php. Below is some of my code I have made, based on other examples I found on net.

AJAX

$('.button').on('click', function(){
    alert('click!');

    $.ajax({
        type: 'POST',
        data: {
          nrTel: nrTel,
          wiadomosc: code
        },
        url: 'soap.php',
        success: function(response){
          console.log(response);
          alert('sukces');
        },
        error: function(response){
          console.log(response);
          alert('error');
        },
    });

  });

PHP

<?php

$wsdl = 'http://89.234.196.188:81/SMS.asmx?WSDL';

$trace = true;
$exceptions = true;

$client = new SoapClient($wsdl, array('trace' => $trace, 'exceptions' =>$exceptions));

$xml_array['user'] = '';
$xml_array['pass'] = '';
$xml_array['phoneNumber'] = $_POST['telephone'];
$xml_array['message'] = $_POST['message'];

try
{
   $client = new SoapClient($wsdl, array('trace' => $trace, 'exceptions' => $exceptions));
   $response = $client->Send($xml_array);
}

catch (Exception $e)
{
   echo "Error!";
   echo $e -> getMessage ();
   echo 'Last response: '. $client->__getLastResponse();
}

var_dump($response);

?>

The problem is that once I click button I get POST 500 (Internal Server Error).

Here is Soap requests...

POST /SMS.asmx HTTP/1.1
Host: 89.234.196.188
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://cpit.pl/Send"

<?xml version="1.0" encoding="utf-8"?>
<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>
    <Send xmlns="http://cpit.pl/">
      <userName>string</userName>
      <password>string</password>
      <phoneNumber>string</phoneNumber>
      <message>string</message>
    </Send>
  </soap:Body>
</soap:Envelope>

and response

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<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>
    <SendResponse xmlns="http://cpit.pl/" />
  </soap:Body>
</soap:Envelope>

I don't have much experience in PHP and Soap so any help would by appreciated.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c