尝试从GWT中的服务器端发送http请求

时间:2014-01-07 16:02:07

标签: gwt

我正在尝试从我的GWT应用程序向服务器发出http请求

以下是我正在使用的代码,它可以在客户端正常工作..

但我想从服务器端这样做..

如果我能得到一些解决方案

     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.html

1 个答案:

答案 0 :(得分:2)

com.google.gwt.http。客户端 .RequestBuilder旨在用于GWT客户端。

要让您的服务器端代码发出HTTP请求,我建议您使用Apache HttpClient library