The NoteBook of EricKong

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            611 Posts :: 1 Stories :: 190 Comments :: 0 Trackbacks
          package com.test.socket;
          import java.io.*;
          import java.net.*;
           
          public class HTTPSocket
            {
                public static void main(String[ ] args) throws UnknownHostException, IOException
               {
                    String host = "127.0.0.1";
                    int port = 8080;
                    Socket socket = new Socket(host, port);
                    
                    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
                    BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                    
                    StringBuffer sb = new StringBuffer();
                    //請求的連接地址
                    sb.append("GET /PortalGuard/Index.jsp HTTP/1.1\r\n")
                     .append("Host:"+ host + "\r\n")
                      .append("Content-Type:application/x-www-form-urlencoded\r\n")
                      .append("Content-Length:11\r\n")            //11 這個數值是看底下內容的長度的 即多少個字符
                      .append("\r\n")
                      .append("id=01234567\r\n");                  //內容
                    
                    out.write(sb.toString());
                    out.flush();
                    
                    //打印響應
                    String line = "";
                    while((line = in.readLine()) != null)
                        System.out.println(line);
                }
            }
          posted on 2013-11-29 10:13 Eric_jiang 閱讀(409) 評論(0)  編輯  收藏 所屬分類: tomcat
          主站蜘蛛池模板: 土默特右旗| 类乌齐县| 从化市| 高安市| 玉田县| 浦县| 齐河县| 广宁县| 什邡市| 靖边县| 通许县| 五家渠市| 通山县| 澄城县| 九江市| 肇东市| 宜宾县| 彭泽县| 遂溪县| 岳普湖县| 兴宁市| 福贡县| 河南省| 环江| 余干县| 团风县| 仪陇县| 临海市| 惠州市| 搜索| 东方市| 三门县| 玉田县| 金堂县| 突泉县| 横峰县| 海晏县| 罗平县| 平凉市| 锦州市| 镇远县|