1

在我的 HTML5 应用程序中,当我尝试调用 SOAP Web 服务时出现“不支持的媒体类型”错误。

这是我的javascript函数的代码。

function login()
{
    var soapMessage = '<?xml version="1.0" encoding="UTF-8"?>'+
    '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:blu="http://www.bluedoortech.com/">'+
    '<soapenv:Header/>'+
    '<soapenv:Body>'+
        '<blu:Connect>'+
            '<blu:userID>' +  $("#txtUserName").val() + '</blu:userID>'+
            '<blu:pwd>' + $("#txtPassword").val() + '</blu:pwd>'+
        '</blu:Connect>'+
    '</soapenv:Body>'+
    '</soapenv:Envelope>';


    $.ajax({
        url : 'Wealth.asmx' ,
        data: soapMessage,
        type: "POST",
        dataType: "xml", 
        cache : false,
        processData: false
    }).success(function(xmlDoc,textStatus) {
        alert($(xmlDoc).text());
    });
}[1]

在这里,我还附上了错误屏幕。

出于测试目的,我制作了一个 php 文件,并使用该 php 文件来调用此 SOAP Web 服务。当我连接到网络服务时,它工作得很好。这是PHP代码。

        header("Content-type: text/xml"); 
        $soap_request = file_get_contents('php://input');

        $xml = simplexml_load_string($soap_request);

        $userIDTag = $xml->xpath('//blu:userID');
        $userID = $userIDTag[0][0];

        $passwordIDTag = $xml->xpath('//blu:pwd');
        $password = $passwordIDTag[0][0];

        $client = new SoapClient("Wealth.asmx?WSDL", array('trace' => true));
        $objLogin =  $client->Connect(array('userID'=>$userID,'pwd'=>$password));

        echo $client->__getLastResponse();

请帮助我确定问题。

4

1 回答 1

3

正如 Joachim Isaksson 建议的那样,我已经添加了内容类型标题,它现在运行良好。我也在这里张贴。

function login()
{
    var soapMessage = '<?xml version="1.0" encoding="UTF-8"?>'+
    '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:blu="http://www.bluedoortech.com/">'+
    '<soapenv:Header/>'+
    '<soapenv:Body>'+
        '<blu:Connect>'+
            '<blu:userID>' +  $("#txtUserName").val() + '</blu:userID>'+
            '<blu:pwd>' + $("#txtPassword").val() + '</blu:pwd>'+
        '</blu:Connect>'+
    '</soapenv:Body>'+
    '</soapenv:Envelope>';


    $.ajax({
        url : 'Wealth.asmx' ,
        data: soapMessage,
        headers: {
            "Content-Type":"text/xml"
        },
        type: "POST",
        dataType: "xml", 
        cache : false,
        processData: false
    }).success(function(xmlDoc,textStatus) {
        alert($(xmlDoc).text());
    });
}
于 2013-03-21T03:34:02.380 回答