血的教訓: http protocol is not supported
阿新 • • 發佈:2018-12-12
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 後面多加個空格,空格,空格,然後程式執行的時候就報了org.apache.http.conn.UnsupportedSchemeException: http protocol is not supported 的異常。然後把http後面的空格去掉問題就解決了(程式裡面還是要加上去空格啊)。。。。。。