启用了代理的我的curl请求有效,但是我的Java代码不起作用。有任何想法可以帮助
卷曲代码(有效)
export https_proxy="test.com:80"
curl https://myurul.com
Java代码
String url = "https://myurl.com";
URL obj = new URL(url);
Properties sys = System.getProperties();
sys.setProperty("https.proxyHost","test.com");
sys.setProperty("https.proxyPort","443");
HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
// optional default is GET
con.setRequestMethod("GET");
int responseCode = con.getResponseCode();
System.out.println("\nSending 'GET' request to URL : " + url);
System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
//print result
System.out.println(response.toString());