本文介绍了使用Solr的3.5和4.2的HttpClient的问题进行查询的Solr通过的HttpClient的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想查询使用的HttpClient我的本地Solr的服务器,我想不通为什么参数没有被添加到 GET 电话。

I am trying to query my local Solr server using HttpClient and I cannot figure out why the parameters are not being added to the GET call.

我的code这样做是这样的:

My code for doing this is:

HttpRequestBase request = new HttpGet("http://localhost:8080/solr/select");

HttpParams params = new BasicHttpParams();
params.setParameter("q", query);
params.setParameter("start", String.valueOf(start));
params.setParameter("rows", String.valueOf(rows));

request.setParams(params);

HttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);

HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();

return stringToStreamConversion(is); //500 error, NullPointerException, response is empty

我试图在看到我会得到并试图找出其中的问题是,希望返回几件事情。我终于意识到,我只是取回的http://本地主机:8080 / Solr的/选择当我回到

返回request.getURI()的toURL()的toString();

我不明白,为什么没有得到补充的参数。如果我做

I cannot figure out why the parameters are not getting added. If I do

返回request.getQuery();

我什么也没有回来...任何想法?感谢您提前帮助!

I get nothing back...any ideas? Thanks for the help in advance!

推荐答案

更​​简单的选择是使用我的,像这样的:

The simpler option is to use the approach I used in HTTPPostScheduler, like this:

URL url = new URL(completeUrl);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();

conn.setRequestMethod("POST");
conn.setRequestProperty("type", "submit");
conn.setDoOutput(true);

// Send HTTP POST
conn.connect();

这篇关于使用Solr的3.5和4.2的HttpClient的问题进行查询的Solr通过的HttpClient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 19:49