我想从我的网络服务器获得回复。所以我发送一个GET命令到我的api路径" auftraege",但是在xhht.send是一个错误"状态代码400"。服务器有一个控制器,用于监听" auftraege"并且只回应"你好"。
var xmlDoc = null;
function loadXML() {
var xhttp;
if (window.XMLHttpRequest) {
xhttp = new XMLHttpRequest();
} else {
xhttp = new ActiveXObject('Microsoft.XMLDOM');
}
xhttp.onreadystatechange = function () {
if (this.readyState === 4 && this.status === 400) {
updateXML(this);
}
};
xhttp.open("GET", "auftraege", true);
xhttp.send('grant_type=client_credentials');
}
function updateXML(xml) {
xmlDoc = xml.responseText;
document.getElementById("auftraege").innerHTML = xmlDoc;
setTimeout(updateTime, 5000);
}
window.addEventListener("load", loadXML);
那是控制器:
[RestController(InstanceCreationType.Singleton)]
public class AuftraegeController {
[UriFormat("/auftraege")]
public IGetResponse GetWithSimpleParameters() {
return new GetResponse( GetResponse.ResponseStatus.OK, "Hello");
}
这是网络服务器
private HttpServer _httpServer;
public async Task InitializeWebServer()
{
var restRouteHandler = new RestRouteHandler();
restRouteHandler.RegisterController<AuftraegeController>();
var configuration = new HttpServerConfiguration()
.ListenOnPort(80)
//.RegisterRoute("api", restRouteHandler)
.RegisterRoute("/auftraege", restRouteHandler)
.RegisterRoute(new StaticFileRouteHandler(@"Web"))
.EnableCors();
var httpServer = new HttpServer(configuration);
_httpServer = httpServer;
await httpServer.StartServerAsync();