gpt4 book ai didi

Solr 将 CommonsHttpSolrServer 更改为 HttpSolrServer

转载 作者:行者123 更新时间:2023-12-04 17:10:57 30 4
gpt4 key购买 nike

对于 solr 3.5 中的基本身份验证,我使用以下代码,

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 .谁能帮我解决这个问题?

最佳答案

更改代码如下:

import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.solr.client.solrj.impl.HttpSolrServer;

String url = "http://192.168.192.11:8080/solr/FormResponses";
HttpSolrServer server = new HttpSolrServer( url );
DefaultHttpClient client = (DefaultHttpClient) server.getHttpClient();

UsernamePasswordCredentials defaultcreds = new UsernamePasswordCredentials("user", "user123");
client.getCredentialsProvider().setCredentials(AuthScope.ANY, defaultcreds);

对于 server.getHttpClient().getParams().setAuthenticationPreemptive(true)在 HttpClient 4 中,您可以使用描述的解决方案 here .

关于Solr 将 CommonsHttpSolrServer 更改为 HttpSolrServer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13987920/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com