URL url = new URL("http://www.baidu.com");
connection = (HttpURLConnection)url.openConnection();
connection.setDoOutput(true);
        connection.setDoInput(true);
        connection.setRequestMethod("POST");
        connection.setUseCaches(false);
        connection.setInstanceFollowRedirects(true);
        connection.setRequestProperty("Content-Type",
                "application/x-www-form-urlencoded");
int code = connection.getResponseCode();   
 System.out.println("----code------"+code);

解决方案 »

  1.   

    爲什麽 code返回的是501呢 但是網上他們都是這麼弄的呀
      

  2.   

    // connection.setDoOutput(true);
    // connection.setDoInput(true);
    // connection.setRequestMethod("POST");
    // connection.setUseCaches(false);
    // connection.setInstanceFollowRedirects(true);
    这都是多余了的。
      

  3.   

    501 Not Implemented
    服务器不支持当前请求所需要的某个功能。当服务器无法识别请求的方法,并且无法支持其对任何资源的请求。你要尽量少的控制请求的参数!
      

  4.   

    爲什麽多餘的 我知道get方式可以去請求 但是我想知道爲什麽post就不行