Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java GWT&x27;s http请求生成器返回空响应_Java_Gwt_Httprequest_Http Get - Fatal编程技术网

Java GWT&x27;s http请求生成器返回空响应

Java GWT&x27;s http请求生成器返回空响应,java,gwt,httprequest,http-get,Java,Gwt,Httprequest,Http Get,我有一个GWT应用程序,我想用它从endomondo获取JSON格式的数据,我可以通过以下IRL获得它: http://api.mobile.endomondo.com/mobile/api/workout/list?authToken=XXXXXXXXXX 我会得到这样的数据 {"data":[{"duration_sec":2710,"sport":0,"speed_kmh_avg":11.721935764889876,"device_workout_id":"6588152507813

我有一个GWT应用程序,我想用它从endomondo获取JSON格式的数据,我可以通过以下IRL获得它:

http://api.mobile.endomondo.com/mobile/api/workout/list?authToken=XXXXXXXXXX
我会得到这样的数据

{"data":[{"duration_sec":2710,"sport":0,"speed_kmh_avg":11.721935764889876,"device_workout_id":"6588152507813057122","feed_id":155634169,"sport2":0,"id":192960126,"altitude_m_max":227.3,"hydration":0.35771,"altitude_m_min":145.5,"has_playlist":false,"burgers_burned":1.075926,"start_time":"2013-05-21 18:57:04 UTC","calories":581,"speed_kmh_max":26.281,"distance_km":8.824012756347656,"has_points":true},]}
但不知何故,通过使用GWT http请求生成器调用此命令,我无法做到这一点。我应该在代码中更改什么

String url = "http://api.mobile.endomondo.com/mobile/api/workout/list?authToken=XXXXXXXXXX";
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);


try {
      Request myrequest = 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()) {
              trainingsJSON = JSONParser.parseStrict(response.getText());
              trainingsString = response.getText();
            Label l = new Label();
            l.setText("200 erros status code JSON DATA from endomondo " + response.getText()) ;

            RootPanel.get().add(l);
          } else {
            // Handle the error.  Can get the status text from response.getStatusText()
                Label l = new Label();
                l.setText("JSON DATA from endomondo 3rror part " + response.getText()) ;

                RootPanel.get().add(l);                   
          }
        }       
      });
    } catch (RequestException e) {
      // Couldn't connect to server        
    }
编辑

我试着添加

builder.setHeader(“访问控制允许原点”,“*”)


但是没有运气。

当您使用GWT发出CORS请求时,您不必在请求中添加任何额外的头。您必须做的是检查服务器是否支持来自您站点的CORS请求

如果您正在管理网站
http://api.mobile.endomondo.com
,当客户端发送
选项
请求时,您必须更改服务器代码以返回相应的CORS头

对于java服务器端,您有一个如何使用
过滤器处理COR的示例


请注意,CORS仅适用于现代浏览器(编辑:某些浏览器的旧版本实际上支持CORS。请参阅下面@Thomas comments中的浏览器列表)。

注意:“现代浏览器”指的是每一种浏览器(Firefox、Chrome、Safari多年来的浏览器、Opera最近的浏览器),但IE9-(IE10很好)。是的,IE9不在“我的”现代浏览器列表中。感谢ThomasI,我还想指出,这里的“现代”浏览器包括已有多年历史的浏览器(Firefox 3.5、Safari 4.0、Chrome–所有版本?至少从4.0开始,Android 2.1)