血的教训: http protocol is not supported

httpclient 添加正向代理设置,程序报错:

org.apache.http.conn.UnsupportedSchemeException: http  protocol is not supported

HttpPost httpPost = new HttpPost(serviceUrl);// 目标服务器
httpPost.addHeader("Content-type","application/json; charset=utf-8");
httpPost.setHeader("Accept", "application/json");
			 
HttpHost proxy = new HttpHost(WalletConfig.PROXY_HOSTNAME, Integer.valueOf(WalletConfig.PROXY_PORT), WalletConfig.PROXY_PROTOCOL_TYPE);// 代理服务器
RequestConfig config = RequestConfig.custom().setProxy(proxy).build();
httpPost.setConfig(config);//设置代理配置

查了一天多,最后发现是运维配置代理协议类型的时候,在properties配置文件里面把 http 后面多加个空格,空格,空格,导致读属性文件得到的字段WalletConfig.PROXY_PROTOCOL_TYPE变成了"http ",然后程序执行的时候就报了org.apache.http.conn.UnsupportedSchemeException: http  protocol is not supported 的异常。把http后面的空格去掉问题就解决了(程序里面还是要加上去空格啊)。。。。。。

血的教训: http protocol is not supported_第1张图片

你可能感兴趣的:(遇到的那些坑)