Solr 将 CommonsHttpSolrServer 更改为 HttpSolrServer [英] Solr Change CommonsHttpSolrServer To HttpSolrServer
本文介绍了Solr 将 CommonsHttpSolrServer 更改为 HttpSolrServer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于 solr 3.5 中的基本身份验证,我使用以下代码,
For Basic Authentication in solr 3.5 I am using the following code,
String url = "http://192.168.192.11:8080/solr/FormResponses";
CommonsHttpSolrServer server = new CommonsHttpSolrServer( url );
String username = "user";
String password = "user123";
Credentials defaultcreds = new UsernamePasswordCredentials(username, password);
server.getHttpClient().getState().setCredentials(AuthScope.ANY, defaultcreds);
server.getHttpClient().getParams().setAuthenticationPreemptive(true);
在 solr 4.0 CommonsHttpSolrServer
不可用,所以我想用HttpSolrServer
.谁能帮我解决这个问题?
In solr 4.0 CommonsHttpSolrServer
is not available, so I want to replace it with
HttpSolrServer
. Can anyone help me to fix this?
推荐答案
我终于找到了自己的答案,
Finally I find the answer my self,
String url = "http://192.168.192.11:8080/solr/FormResponses";
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getCredentialsProvider().setCredentials(
AuthScope.ANY, new UsernamePasswordCredentials("user", "user123"));
SolrServer solrServer = new HttpSolrServer(url, httpclient);
这篇关于Solr 将 CommonsHttpSolrServer 更改为 HttpSolrServer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文