获取网络错误415 - 不支持的媒体类型
问题描述:
在我的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();
请帮助我确定问题。
答
正如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());
});
}
如何将'contentType:“text/xml”'添加到ajax调用中? – 2013-03-20 07:52:57
Joachim Isaksson是正确的:你发送“xml”数据而没有声明它。 Google针对“不支持的媒体类型”:http://www.checkupdown.com/status/E415.html,http://*.com/questions/11492325 ... – LeGEC 2013-03-20 08:12:05
感谢您的回复。我会检查使用这些。 – 2013-03-20 08:45:04