0

我正在尝试使用 HttpClient 查询我的本地 Solr 服务器,但我无法弄清楚为什么没有将参数添加到GET调用中。

我这样做的代码是:

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://localhost:8080/solr/select时候才回来

return request.getURI().toURL().toString();

我无法弄清楚为什么没有添加参数。如果我做

return request.getQuery();

我一无所获……有什么想法吗?我在这里先向您的帮助表示感谢!

4

2 回答 2

0

更简单的选择是使用我在HTTPPostScheduler中使用的方法,如下所示:

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();
于 2012-07-10T07:02:09.687 回答
0

From what I have seen you are not able to associate your paeans with the request.

So, instead of creating a new HttpParams object and associating it with request, can you try the following approach ?

httpCclient.getParams().setParameter("q", query"); ....

于 2012-07-10T02:03:17.303 回答