如题!用Socket来做,谢谢啦!

解决方案 »

  1.   

    下面这个是一个模拟Get方法的页面邀请示例,将get谓词改成post即可。using System;
    using System.Text;
    using System.IO;
    using System.Net;
    using System.Net.Sockets;public class GetSocket
    {
        private static Socket ConnectSocket(string server, int port)
        {
            Socket s = null;
            IPHostEntry hostEntry = null;
            
            // Get host related information.
            hostEntry = Dns.GetHostEntry(server);        // Loop through the AddressList to obtain the supported AddressFamily. This is to avoid
            // an exception that occurs when the host IP Address is not compatible with the address family
            // (typical in the IPv6 case).
            foreach(IPAddress address in hostEntry.AddressList)
            {
                IPEndPoint ipe = new IPEndPoint(address, port);
                Socket tempSocket = 
                    new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);            tempSocket.Connect(ipe);            if(tempSocket.Connected)
                {
                    s = tempSocket;
                    break;
                }
                else
                {
                    continue;
                }
            }
            return s;
        }    // This method requests the home page content for the specified server.
        private static string SocketSendReceive(string server, int port) 
        {
            string request = "GET / HTTP/1.1\r\nHost: " + server + 
                "\r\nConnection: Close\r\n\r\n";
            Byte[] bytesSent = Encoding.ASCII.GetBytes(request);
            Byte[] bytesReceived = new Byte[256];
           
            // Create a socket connection with the specified server and port.
            Socket s = ConnectSocket(server, port);        if (s == null)
                return ("Connection failed");
          
            // Send request to the server.
            s.Send(bytesSent, bytesSent.Length, 0);  
            
            // Receive the server home page content.
            int bytes = 0;
            string page = "Default HTML page on " + server + ":\r\n";        // The following will block until te page is transmitted.
            do {
                bytes = s.Receive(bytesReceived, bytesReceived.Length, 0);
                page = page + Encoding.ASCII.GetString(bytesReceived, 0, bytes);
            }
            while (bytes > 0);
            
            return page;
        }
        
        public static void Main(string[] args) 
        {
            string host;
            int port = 80;        if (args.Length == 0)
                // If no server name is passed as argument to this program, 
                // use the current host name as the default.
                host = Dns.GetHostName();
            else
                host = args[0];        string result = SocketSendReceive(host, port); 
            Console.WriteLine(result);
        }
    }
      

  2.   

    首先谢谢楼上的弟兄,但是这个还是不符合我的要求。(怪我刚才没有讲清楚)现在再明确一下,假如我有一个网页地址是http://www.163.com/Login.aspx,在这个页面接受其他页面里面用Form方式提交过去的UserName和Password来让用户登录,在IE下面非常方便的实现,现在想要用Socket来自己做一个软件,也让它模拟IE处理类似的操作。请各位指教,谢谢!
      

  3.   

    这个要详细查看http协议,然后根据协议中的规则来post数据.
      

  4.   

    我认为实现的可能性不大.
    因为:Web提交数据时,始终是以Form方式的,这也是IE的工作方式.如果你要用C/S来模拟那个操作,我看没什么必要!
      

  5.   

    谁告诉你用 socket的?
    不用不行啊?
    .net中 winform模拟post 已经是成型的技术
    参看HttpWebRequest 与HttpWebResponse类, 如需要代码 消息联系我