Java ASP Post


詳細
Javaで編纂する模擬ASP Postは書く1つの上海の違法な検索の例を書くことを求めます
 
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;

public class TestPost {
    public static void testPost() throws IOException {
        URL url = new URL("http://www.shjtaq.com/zwfg/dzjc_new.asp");
        URLConnection connection = url.openConnection();
        /**
         *            。URLConnection         ,      Web 。
         *    URLConnection    ,         Web   。      :
         */
        connection.setDoOutput(true);
        /**
         *   ,    OutputStream,    ,     Writer    POST   ,  : ...
         */
        OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "gb2312");
        out.write("cardqz= &carnumber=   &type1=02/      &fdjh=    &act=search"); //       。post     !
        // remember to clean up
        out.flush();
        out.close();

        //       ,                :
        StringBuffer webpage = new StringBuffer();
        InputStream in = connection.getInputStream();
        while (((in.read()) != -1)) {
            int all = in.available();
            byte[] b = new byte[all];
            in.read(b);

            webpage.append(new String(b, "gb2312"));
        }
        in.close();

        System.out.println(webpage);
   }

    public static void main(String[] args) throws IOException {
        testPost();
    }
}