转发:
目标:
我正在使用GWT,并尝试使用RestyGWT客户端调用现有的Twitter REST服务
问题:
我没有收到对"https://api.twitter.com/1.1/statuses/mentions_timeline.json",或另一个json.
我尝试过的东西:
我看了RestyGWT的文档,没有找到一个关于如何调用第三方REST服务的具体示例。尝试使用纯文本返回类型调用REST服务,同样的问题。从根本上讲,我一定做错了什么。
代码:
这是我的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:tt"+exception.toString());
System.out.println("Exception Message:t"+exception.getMessage());
System.out.println("Status code:tt"+method.getResponse().getStatusCode() );
}
});}
输出:
GWT MODULE LOADED
Twitter response: NO
Exception: org.fusesource.restygwt.client.FailedStatusCodeException:
Exception Message:
Status code: 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>