0

我尝试从此网址获取字符串:
http ://autoc.finance.yahoo.com/autoc?query=google&callback=YAHOO.Finance.SymbolSuggest.ssCallback

当我在 Chrome 中查看此内容时,我看到了正确的 JavaScript 响应,但是当从具有相同标头的应用程序下载它时,我得到了二进制响应。如何在应用程序中获得相同的正确响应?

编辑: 代码:

public RESTResponse<T> get(String url) {
    HttpGet get = new HttpGet(url);
    setHeaders(get);
    return execute(get);
}                                                         

private void setHeaders(HttpRequestBase request) {
    request.setHeader("Accept", "text/html,application/xhtml+xml,application/xml");
    request.setHeader("Accept-Encoding", "gzip,deflate,sdch");
    request.setHeader("Accept-Charset", "UTF-8");
}

private RESTResponse<T> execute(HttpRequestBase request) {
    DefaultHttpClient client = new DefaultHttpClient();
    try {
        HttpResponse response = client.execute(request);
        return responseFactory.create(response);
    } catch (IOException e) {
        throw new RuntimeException("Can't perform request.", e);
    }
}
4

1 回答 1

1

很难在没有看到您的代码的情况下说出问题所在 - 但您可以使用该代码:

https://github.com/ligi/LigiAndroidCommons/blob/master/src/org/ligi/android/common/net/NetHelper.java

于 2012-04-08T12:06:46.297 回答