保持HTTP连接在C#中还活着吗? [英] Keep a http connection alive in C#?

查看:295
本文介绍了保持HTTP连接在C#中还活着吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应如何在C#中活着的连接?我不这样做是正确的。我是想创建一个HttpWebRequest的OBJ,并用它去,我需要的网址吗?我没有看到一个方法来访问其它的URL则HttpWebRequest.Create静态方法。



如何创建一个连接,保持它活着,在浏览多个网页/媒体页面和支持proxys? (我听到代理很容易和支持,几乎是标准?)
-edit-很好的答案。我该如何申请第二个网址?

  {
HttpWebRequest的WebRequestObject =(HttpWebRequest的)HttpWebRequest.Create(http://google.com);
WebRequestObject.KeepAlive = TRUE;
//做的东西
WebRequestObject.Something(http://www.google.com/intl/en_ALL/images/logo.gif);
}


解决方案

您是否尝试过的<一个HREF =htt​​p://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.keepalive.aspx> HttpWebRequest.KeepAlive 的财产?它设置适当的保持活动的HTTP标头不持续的连接。 (当然,这也必须得到支持并通过远程Web服务器启用)。



HttpWebRequest.KeepAlive 在MSDN文档指出它是默认的HTTP1.1连接设置为真正,所以我怀疑你试图联系不允许连接持久服务器。



代理会自动使用和设置从您的系统采取(读Internet Explorer)中的设置。它也可以覆盖通过 HttpWebRequest.Proxy 物业代理服务器设置或者通过调整应用程序配置文件(请参见 http://msdn.microsoft.com/en-us/library /kd3cf2ex.aspx )。


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 a url other then the HttpWebRequest.Create static method.

How do i create a connection, keep it alive, browse multiple pages/media on the page and support proxys? (i hear proxy are easy and support is almost standard?) -edit- good answers. How do i request a 2nd url?

{
HttpWebRequest WebRequestObject = (HttpWebRequest)HttpWebRequest.Create("http://google.com");
WebRequestObject.KeepAlive = true;
//do stuff
WebRequestObject.Something("http://www.google.com/intl/en_ALL/images/logo.gif");
}

解决方案

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).

这篇关于保持HTTP连接在C#中还活着吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆