2014-09-11 42 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>