如何在java中获得与http和https的连接

h43kikqp  于 2021-07-12  发布在  Java
关注(0)|答案(0)|浏览(186)

目前我正在动态发送url,当我向代理发送https://url时,我得到了一个例外

URL url;
              HttpURLConnection connection = null;
              String urlParameters ="key="+licenseKey+"&city="+city+"&state="+state+"&country="+country;
              try {
                //Create connection
                url = new URL(static_location_URL);
                String proxyAddress = GeoLocationQuery.getInstance().getProxyAddress();
                String proxyPort = GeoLocationQuery.getInstance().getProxyPort();
                if(proxyAddress != null && !proxyAddress.isEmpty()) {
                        System.setProperty("http.proxyHost", proxyAddress);
                        System.setProperty("http.proxyPort", proxyPort);
                }
log.error("GOING FOR THE CONNECTION:::::::::::::::::");
                connection = (HttpURLConnection)url.openConnection();
                connection.setConnectTimeout(5000);
                connection.setReadTimeout(5000);
                connection.setRequestMethod("POST");
                connection.setRequestProperty("Content-Type",
                     "application/x-www-form-urlencoded");

                connection.setRequestProperty("Content-Length", "" +
                         Integer.toString(city.getBytes().length));
                connection.setRequestProperty("Content-Language", "en-US");

                connection.setUseCaches (false);
                connection.setDoInput(true);
                connection.setDoOutput(true);

//在此之后,我正在执行发送/接收请求和响应

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题