我尝试从此网址获取字符串:
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);
}
}