如何在GWT开发模式下获取远程服务器的数据?
我是GWT初学者。我在GWT开发模式下调试我的程序。网址是 我想从提供json格式数据的现有服务器获取数据。我的代码是:如何在GWT开发模式下获取远程服务器的数据?,gwt,Gwt,我是GWT初学者。我在GWT开发模式下调试我的程序。网址是 我想从提供json格式数据的现有服务器获取数据。我的代码是: String url = "http://i.abc.com?sid=" + mSessionId + "&action=info"; RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url)); try { Request requ
String url = "http://i.abc.com?sid=" + mSessionId + "&action=info";
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url));
try {
Request request = builder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable exception) {
// Couldn't connect to server (could be timeout, SOP
// violation, etc.)
Window.alert("Get fudao info error");
mPrepare = false;
}
@Override
public void onResponseReceived(Request request, Response response) {
GWT.log("statuscode:"+response.getStatusCode());
if (200 == response.getStatusCode()) {
// Process the response in response.getText()
Window.alert(response.getText());
mPrepare = true;
} else {
// Handle the error. Can get the status text from
// response.getStatusText()
Window.alert("Get fudao info wrong");
mPrepare = false;
}
}
});
} catch (RequestException e) {
// Couldn't connect to server
}
运行应用程序时,请求失败,其状态为“已取消”。这是我无法从localhost请求远程服务器地址以满足SOP限制的原因吗
如何在GWT开发模式下获取远程服务器的数据?通常无法从其他服务器获取GWT客户端代码中的数据。但是您的本地服务器可以充当代理,例如,您向本地服务器发送请求,它将向远程服务器发送请求,然后从远程服务器获得响应并将其发送给GWT客户端代码。这基本上是最简单的解决方案 您是希望仅在开发模式下从远程服务器获取数据,还是希望在生产模式下也这样做?您听说过“同源”策略吗?如果没有,请阅读以下内容: