2

转发:

客观的:

我正在使用 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    
4

1 回答 1

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>
于 2014-09-16T09:25:29.217 回答