我一直在尝试使用 REST api 从 Dynatrace 服务器获取 XML 响应。当我通过 Postman 输入 url 时,我可以毫无问题地获得 XML 响应,并且我能够接收'text'
来自 ajax 的数据类型响应,但不能接收'xml'
响应。我计划将这些数据解析为 json 以备将来使用。
到目前为止我使用的代码是:
function getXML() {
basicAuth = "Basic " + id + ":" + password;
$.ajaxSetup({
async: false
});
$.ajax({
type: 'GET',
url: dynUrl, //this is the function we defined above
dataType: 'xml',
headers: {
'Authorization': basicAuth //this is for basic authentication, you've already provided UID and PWD above.
},
//when we succeed, the function below will be called.
success: function(respt)
{
data = respt;
}
});
}
这在以下函数中调用。
function XMLRespond()
{
getXML();
//dom = parseXml(data);
//json = xmlToJson(dom);
return data;
}
data
由托管在 localhost 上的 html 调用和显示。但是,当我运行它时,我得到一个空白屏幕,并且控制台显示“Permission Denied”。我的调试器给了我:
Failed to open http://localhost:8080/api/Test.html
对此问题的任何帮助将不胜感激!