java RestyGWT和GWT集成:无法获取资源
目标:
我正在使用GWT,并尝试使用RestyGWT客户端调用现有的Twitter REST服务
问题:
我没有收到对“https://api.twitter.com/1.1/statuses/mentions_timeline.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
# 1 楼答案
如果您正在访问一个不是您的远程服务,您通常必须发送JSONP请求来处理同一源策略。因此,尝试
r.jsonp()
而不是r.get()
# 2 楼答案
jsonp至少调用服务方法,但异常状态代码为0。然而,get甚至没有到达服务方法