试图在GWT中从服务器端发送httpRequest
我正试图从GWT应用程序向服务器发出http请求 下面是我正在使用的代码,它在客户端运行良好 但我想从服务器端执行此操作 如果我能找到解决办法的话试图在GWT中从服务器端发送httpRequest,gwt,Gwt,我正试图从GWT应用程序向服务器发出http请求 下面是我正在使用的代码,它在客户端运行良好 但我想从服务器端执行此操作 如果我能找到解决办法的话 String url = "http://www.myserver.com/getData?type=3"; RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url)); try { Request r
String url = "http://www.myserver.com/getData?type=3";
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.)
}
public void onResponseReceived(Request request, Response response) {
if (200 == response.getStatusCode()) {
// Process the response in response.getText()
} else {
// Handle the error. Can get the status text from response.getStatusText()
}
}
});
} catch (RequestException e) {
// Couldn't connect to server
}
参考:www.gwtproject.org/doc/latest/DevGuideServerCommunication.htmlcom.google.gwt.http.客户端。RequestBuilder用于gwt客户端
对于用于发出HTTP请求的服务器端代码,我建议使用。您可以使用任何rest客户端。。就像ApacheHTTP那样