如何从TcpClient获取表单数据

时间:2016-11-16 16:20:58

标签: c# webserver tcpclient

我创建了一个简单的网络服务器,当你连接它时,它会提供HTML文件。

我创建了一个简单的表单,现在为什么我得到表格参数,我试着继续阅读请求,但我找不到它..

这就是我能读到的全部内容: Request Data from client

我用来从客户端读取的代码:

while(true) 
{
    Console.WriteLine("Waiting for next request...");
    TcpClient client = listener.AcceptTcpClient();
    StreamReader sr = new StreamReader(client.GetStream());
    StreamWriter sw = new StreamWriter(client.GetStream());

    try 
    {
        string req = sr.ReadLine();

        for(int i = 0; i < 11; i++) {
            string header = sr.ReadLine();
            Console.WriteLine(header);
        }


        string[] toks = req.Split(' ');
        Console.WriteLine("");
        Console.WriteLine("Request Method: " + toks[0]);
        Console.WriteLine("Request File: " + toks[1]);
        Console.WriteLine("Response: " + toks[2]);
        Console.WriteLine("");
        string page = toks[1];
        //Serving files&catch comes here...
}

0 个答案:

没有答案