简体   繁体   中英

Http Post request using tcpClient using proxy

II have to send http post data to a website throw a proxy and receive the server response. For example, I want to send the request

request=Encoding.ASCII.GetBytes("POST / HTTP/1.1\r\nHost: example.com\r\nConnection: Close\r\n\r\ntest_check=Hello");

In my site, I check if the post data is well sended. In this case, I return "Ok". First, I writte something like this:

TcpClient client = new TcpClient(host, port);
NetworkStream stream = client.GetStream();
stream.Write(request, 0, request.Length);
stream.Flush();
while ((count = stream.Read(buffer, 0, buffer.Length)) > 0)
            response.Append(encoder.GetString(buffer, 0, count));

The response is empty. What wrong?

After that will worked, I want to send the request via TcpCLient of a proxy server. Is it possible?

Thanks

由于使用的是HTTP协议,因此应使用HttpWebRequest类,该类确实支持使用WebProxy类设置代理。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM