做Http Post
/* 来自 n o w j a v a . c o m*/ //package com.nowjava; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; public class Main { public static void main(String[] argv) throws Exception {// 来自 时 代 J a v a - nowjava.com String url = "nowjava.com"; String request = "nowjava.com"; System.out.println(doHttpPost(url, request)); } public static String doHttpPost(String url, String request) throws MalformedURLException, IOException { // establish connection and send request HttpURLConnection connection = (HttpURLConnection) new URL(url) .openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Length", String.valueOf(request.length())); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setDoOutput(true); connection.setDoInput(true); // write request BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( connection.getOutputStream())); writer.write(request); writer.flush(); // read response BufferedReader reader =