java ik分词 HttpResponseProxy{HTTP/1.1 401 Unauthorized

之前一直好好的,自从公司搬个家之后就不行了,通过url访问ik分词的时候会直接报401

		// 从客户端发送HTTP请求到服务器端,
		CloseableHttpClient httpClient = HttpClients.createDefault();
		String analyzer = "";
		int analyzerType = 0;
		if (analyzerType == 0) {
			analyzer = "ik_smart";
		} else {
			analyzer = "ik_max_word";
		}
		HttpPost httpPost = new HttpPost(Constant.SEARCH_URL
				+ "/omoappkeyword/_analyze?analyzer=" + analyzer
				+ "&pretty=true&text="
				+ URLEncoder.encode(queryString, "utf-8"));
        httpPost.addHeader("User-Agent", USER_AGENT);
		CloseableHttpResponse httpResponse = null;
		
		String enc = "username:password";
		httpPost.addHeader("Authorization", "Basic " + new Base64Encoder().encode(enc.getBytes()));

//		List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
//		urlParameters.add(new BasicNameValuePair("shanjin", "shanjin"));
//		HttpEntity postParams = new UrlEncodedFormEntity(urlParameters);
//		httpPost.setEntity(postParams);
		
		// 发送get请求
		httpResponse = httpClient.execute(httpPost, credentialContext);

其中

		String enc = "username:password";
		httpPost.addHeader("Authorization", "Basic " + new Base64Encoder().encode(enc.getBytes()));
是本次加进去的解决方法


		String enc = "username:password";
		httpPost.addHeader("Authorization", "Basic " + new Base64Encoder().encode(enc.getBytes()));
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值