2014-09-11 87 views
2

转贴:RestyGWT和GWT整合

目的:

我使用GWT,并试图在现有的Twitter REST服务使用RestyGWT客户

问题打电话:

我没有收到我对“https://api.twitter.com/1.1/statuses/mentions_timeline.json”或其他json的GET请求的回复。

事情我已经尝试:

我已经看了RestyGWT的文档,我无法跨越上如何调用第三方REST服务一个具体的例子来。尝试使用纯文本返回类型调用REST服务,同样的问题。必须有一些我在基本层面上做错了。

CODE:

这里是我的onModuleLoad:

public void onModuleLoad() { 

Resource r = new Resource("https://api.twitter.com/1.1/statuses/mentions_timeline.json"); 

     r.get().send(new JsonCallback() { 

      @Override 
      public void onSuccess(Method method, JSONValue response) { 
       System.out.println("Twitter response:\tYES"); 
       } 

      @Override 
      public void onFailure(Method method, Throwable exception) { 
       System.out.println("Twitter response:\tNO"); 
       System.out.println("Exception:\t\t"+exception.toString()); 
       System.out.println("Exception Message:\t"+exception.getMessage()); 
       System.out.println("Status code:\t\t"+method.getResponse().getStatusCode()); 
       } 
     });} 

OUTPUT:

GWT MODULE LOADED 
Twitter response: NO 
Exception:   org.fusesource.restygwt.client.FailedStatusCodeException: 
Exception Message: 
Status code:  0  
+0

你正在尝试做一个跨站请求,首先看看http://crazygui.wordpress.com/2012/08/08/cross-site-requests-with-gwt -restygwt和-HTML5-CORS/ 也许https://groups.google.com/forum/#!searchin/restygwt/csrf/restygwt/C6F6VXx_A6A/VvQfbmFlBH4J 然后,你需要进行身份验证,此调用。如果未通过身份验证,您应该收到215错误。 – 2014-09-22 12:06:52

回答

0

这可能是在您的要求 “_” 符号引起的。尝试使用另一个URL,或者在web.xml中的服务器端添加CharacterEncodingFilter。这样的事情:

 <filter> 
    <filter-name>encoding-filter</filter-name> 
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 
    <async-supported>true</async-supported> 
    <init-param> 
     <param-name>encoding</param-name> 
     <param-value>UTF-8</param-value> 
    </init-param> 
    <init-param> 
     <param-name>forceEncoding</param-name> 
     <param-value>true</param-value> 
    </init-param> 
    </filter> 
    <filter-mapping> 
     <filter-name>encoding-filter</filter-name> 
    <url-pattern>/*</url-pattern> 
    </filter-mapping>