【发布时间】:2015-06-12 09:02:20
【问题描述】:
我目前使用的日历系统具有可以通过 SOAP 请求访问的 API。它存在于 IIS 服务器上。
最初我想我可以创建一个 HTML 页面,然后我可以使用 Javascript 来返回 SOAP 请求的内容 - 我的 SOAP 请求完全返回我想要的内容,但不是在有效的 XML 中 - 它只是显示在屏幕上(目前已在下方注释掉)。
我需要知道的是如何让页面只返回有效的 XML 响应(没有其他标签,因此它被识别为 XML)? PHP 会更适合这个 - 还是 ASP?
我当前的 javascript 看起来像这样:
function soap() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', 'http://myserver/EMSAPI/', true);
//Todays Date now = new Date();
year = "" + now.getFullYear();
month = "" + (now.getMonth() + 1); if (month.length == 1) { month = "0" + month; }
day = "" + now.getDate(); if (day.length == 1) { day = "0" + day; }
hour = "" + now.getHours(); if (hour.length == 1) { hour = "0" + hour; }
minute = "" + now.getMinutes(); if (minute.length == 1) { minute = "0" + minute; }
second = "" + now.getSeconds(); if (second.length == 1) { second = "0" + second; }
todaydate = year + "-" + month + "-" + day + "T" + hour + ":" + minute + ":" + second + ".000";
// build SOAP request
var sr =
'<?xml version="1.0" encoding="utf-8"?>' +
'<soap:Envelope ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xmlns:api="http://127.0.0.1/Integrics/Enswitch/API" ' +
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
'<soap:Body>' +
'<GetAllBookings xmlns="http://DEA.EMS.API.Web.Service/">' +
'<UserName>EmsAPI</UserName>' +
'<Password>Mypass</Password>' +
'<StartDate>'+todaydate+'</StartDate>' +
'<EndDate>'+todaydate+'</EndDate>' +
'<BuildingID>36</BuildingID>' +
'<ViewComboRoomComponents>false</ViewComboRoomComponents>' +
'</GetAllBookings>' +
'</soap:Body>' +
'</soap:Envelope>';
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
ret = xmlhttp.responseText;
//$(document.body).append(ret);
}
}
}
// Send the POST request
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
xmlhttp.send(sr);
// send request
// ...
}
window.onload = function() { soap(); };
我的 HTML 非常简单 - 除了包含 javascript 之外,它是一个空白文档。
问题是我正在使用一些无法直接与日历交互的软件——而且该软件只接受有效的 XML 响应——所以无论我写什么页面,它都必须只返回纯 XML,这样当我将页面 URL 告诉软件——它会得到适当的 XML 响应。
只是想知道还有什么其他方法可以让它发挥作用。如果问题令人困惑,我深表歉意 - 如果需要,我可以详细说明。
【问题讨论】:
标签: javascript php html xml soap