Keep a http connection alive in C#?

后端 未结 5 776
后悔当初
后悔当初 2021-01-12 00:04

How do i keep a connection alive in C#? I\'m not doing it right. Am i suppose to create an HttpWebRequest obj and use it to go to any URLs i need? i dont see a way to visit

5条回答
  •  天命终不由人
    2021-01-12 00:43

    Have you tried the HttpWebRequest.KeepAlive property? It sets the appropriate Keep-Alive HTTP header and does persist the connections. (Of course this must also be supported and enabled by the remote web server).

    The HttpWebRequest.KeepAlive documentation on MSDN states that it is set to true by default for HTTP1.1 connections, so I suspect the server you're trying to contact does not allow connection persistence.

    Proxy is used automatically and its settings are taken from your system (read Internet Explorer) settings. It is also possible to override the proxy settings via HttpWebRequest.Proxy property or by tweaking the application configuration file (see http://msdn.microsoft.com/en-us/library/kd3cf2ex.aspx).

提交回复
热议问题