转发:
目标:
我正在使用 GWT 并尝试使用 RestyGWT 客户端调用现有的 Twitter REST 服务
问题:
我没有收到对“https://api.twitter.com/1.1/statuses/mentions_timeline.json”或其他 json 的 GET 请求的响应。
我尝试过的事情:
我查看了 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:\t\t"+exception.toString());
System.out.println("Exception Message:\t"+exception.getMessage());
System.out.println("Status code:\t\t"+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>
关于java - RestyGWT 和 GWT 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25788932/