private String ConnectionHost(String HostName,String Url,int Port,String PostData)
        {
            //解析域名
            IPHostEntry IPHostInfo = Dns.GetHostEntry(HostName);
            //获取域名IP地址
            IPAddress IP = IPHostInfo.AddressList[0];
            IPEndPoint Connection = new IPEndPoint(IP, Port);
            Socket HttpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            HttpSocket.ReceiveTimeout = 4000;
            HttpSocket.Connect(Connection);
            //建立发送报头
            String formatString = "{0}   {1}   HTTP/1.1\r\nContent-Type:   application/x-www-form-urlencoded\r\nContent-Length:   {2}\r\nHost:   {3}\r\n\r\n{4}";
            String SendString = string.Format(formatString, "POST", Url, Encoding.Default.GetByteCount(PostData), HostName, PostData);
            byte[] SendBuffer = System.Text.Encoding.Default.GetBytes(SendString);
            HttpSocket.Send(SendBuffer);
            int Block = 100000;
            byte[] ReceiveBuffer = new byte[Block];
            Block = HttpSocket.Receive(ReceiveBuffer);
            String ReceiveString = System.Text.Encoding.Default.GetString(ReceiveBuffer, 0, Block);
            HttpSocket.Close();
            return ReceiveString;
        }
链接代码登录成功的头
HTTP/1.1 200 OK
Date: Fri, 05 Dec 2008 15:23:00 GMT
Server: Apache
Expires: 0
Cache-Control: private, post-check=0, pre-check=0, max-age=0
Pragma: no-cache
Set-Cookie: cdb_sid=O0UUQI; expires=Sat, 06-Dec-2008 15:23:00 GMT; path=/; domain=.19lou.com; httponly
Set-Cookie: cdb_cookietime=2592000; expires=Sun, 04-Jan-2009 15:23:00 GMT; path=/; domain=.19lou.com; httponly
Set-Cookie: cdb_auth=WlNXAANWD1NVBgMLBw8HVFlWAAFTVFcOAVYFUwYBUVYwaldTU1QODlMF; expires=Sun, 04-Jan-2009 15:23:00 GMT; path=/; domain=.19lou.com; httponly
Vary: Accept-Encoding,User-Agent
Content-Length: 7671
Connection: close
Content-Type: text/html失败的头
HTTP/1.1 200 OK
Date: Fri, 05 Dec 2008 15:27:15 GMT
Server: Apache
Set-Cookie: cdb_sid=n0lyUo; expires=Sat, 06-Dec-2008 15:27:15 GMT; path=/; domain=.19lou.com; httponly
Vary: Accept-Encoding,User-Agent
Content-Length: 4401
Connection: close
Content-Type: text/html如何将登录成功的信息再次加入下一次的包发送呢?

解决方案 »

  1.   

    - -~!取不出
    郁闷死我了...
    Html = Html.Substring(0, Html.IndexOf("\r\n\r\n"));
                textBox1.Text = Html.Substring(Html.IndexOf("Set-Cookie"), Html.LastIndexOf("httponly"));
    我这样取
    程序TMD告诉我超长了...- -~!?
      

  2.   

    或者直接把你返回的ReceiveString插入数据库里面再取,应该可以取出的呀
      

  3.   

    不是
    问题是我要把这个COOKIE发送出去
    怎么写?
    已经取得了Set-Cookie: cdb_sid=8gzmVU; expires=Sat, 06-Dec-2008 15:57:20 GMT; path=/; domain=.19lou.com; httponly
    Set-Cookie: cdb_cookietime=2592000; expires=Sun, 04-Jan-2009 15:57:20 GMT; path=/; domain=.19lou.com; httponly
    Set-Cookie: cdb_auth=WlNXAANWD1NVBgMLBw8HVFlWAAFTVFcOAVYFUwYBUVYwaldTU1QODlMF; expires=Sun, 04-Jan-2009 15:57:20 GMT; path=/; domain=.19lou.com; httponly这个头...加载HTTP头的哪部分?
      

  4.   

    用httpwatch之类的监视工具拦截ie看一下就知道该在怎么写了.