HttpURLConnection.getResponseCode()显示不同java版本的不同行为

时间:2014-04-16 13:32:03

标签: java httpresponse httpurlconnection http-response-codes

您好我使用下面的示例 java 1.6,它正常工作并返回 200 作为响应但是如果我使用 java 1.3 ,我得到回应 407 我的班级:

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Properties;


public class Class1 {
public static void main(String[] args) {

    String url = "http://www.google.com/", 
    proxy = "myproxyserver", 
    port = "myport";
    URL server = null;
    try {
        Properties systemProperties = System.getProperties();
        systemProperties.setProperty("http.proxyHost", proxy);
        systemProperties.setProperty("http.proxyPort", port);
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        server = new URL(url);
    } catch (MalformedURLException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    }

    HttpURLConnection connection = null;
    try {
        connection = (HttpURLConnection) server.openConnection();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    try {
        connection.connect();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        InputStream in = connection.getInputStream();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        System.out.println(connection.getResponseCode());
        System.out.println("done");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}
}

我做错了什么或我需要做些什么才能使用java1.3? 请帮忙。

0 个答案:

没有答案