1
在我的HTML5應用程序中,當我嘗試調用SOAP Web服務時,出現「不支持的媒體類型」錯誤。獲取網絡錯誤415 - 不支持的媒體類型
這是我的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服務。當我連接到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();
請幫助我確定問題。
如何將'contentType:「text/xml」'添加到ajax調用中? – 2013-03-20 07:52:57
Joachim Isaksson是正確的:你發送「xml」數據而沒有聲明它。 Google針對「不支持的媒體類型」:http://www.checkupdown.com/status/E415.html,http://stackoverflow.com/questions/11492325 ... – LeGEC 2013-03-20 08:12:05
感謝您的回覆。我會檢查使用這些。 – 2013-03-20 08:45:04