代理上的TCPClient [英] TCPClient on Proxy

查看:88
本文介绍了代理上的TCPClient的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在作为网络一部分的计算机上工作,并使用代理连接到网络。我无法使用简单的ConnectTo代码连接到代理外部的服务器。我需要知道如何让我的请求通过代理。例如,

_socket = new TcpClient(" http://msdn.microsoft.com" ;, port);

不起作用。

Thanx。

Ab。

解决方案

嗨阿布巴卡尔,


我不是很好的.NET网络东西,但是......

TcpClient构造函数需要一个主机名

(例如msdn .microsoft.com),而不是WWW地址。


问候


Marcin


我在一台计算机上工作,该计算机是网络的一部分,并使用代理连接到网络。我无法使用简单的ConnectTo代码连接到代理外部的服务器。我需要知道如何让我的请求通过代理。例如,
_socket = new TcpClient(" http://msdn.microsoft.com" ;, port);
不起作用。
Thanx。
Ab。


来自MSDN:

如果您的网站使用代理提供对Internet的访问,您必须
配置代理实例以使您的应用程序能够与Web代理进行通信。以下代码示例创建一个全局代理
实例,该实例将使任何WebRequest都能使用代理与Internet通信。该示例假定代理服务器名为webproxy,并且它在端口80(
标准HTTP端口)上进行通信。
[C#] WebProxy proxyObject = new WebProxy(" http:// webproxy:80 /");
GlobalProxySelection.Select = proxyObject;
您可以通过将实现IWebProxy接口的实例分配给
WebRequest的Proxy属性来覆盖全局代理选择。以下代码示例将WebRequest发送到
www.contoso.com ,以覆盖在端口80上使用名为alternateproxy的代理服务器进行全局代理选择。[C#] WebRequest req =
new WebRequest.Create(" http://www.contoso.com/"); req.Proxy = new
WebProxy(" http:// alternateproxy:80 /");


请看以下主题:


- HTTP

- 通过代理访问Internet


玩得开心!


Martin


Abubakar写道:


我在作为网络一部分的计算机上工作,并使用代理连接到网络。我无法使用简单的ConnectTo代码连接到代理外部的服务器。我需要知道如何让我的请求通过代理。例如,
_socket = new TcpClient(" http://msdn.microsoft.com" ;, port);
不起作用。
Thanx。
Ab。


我不想使用WebRequest ,,,我想使用TCPClient。


" mphanke"写道:

来自MSDN:

如果您的网站使用代理提供对Internet的访问,您必须配置一个代理实例,使您的应用程序能够与Web代理进行通信。以下代码示例创建一个全局代理
实例,该实例将使任何WebRequest都能使用代理与Internet通信。该示例假定代理服务器名为webproxy,并且它在端口80(
标准HTTP端口)上进行通信。


[C#] WebProxy proxyObject = new WebProxy(" http:// webproxy:80 /");
GlobalProxySelection.Select = proxyObject;


您可以覆盖通过分配实例来实现全局代理选择,该实例实现了对WebRequest的Proxy属性的IWebProxy接口。以下代码示例将WebRequest发送到
www.contoso.com ,以覆盖在端口80上使用名为alternateproxy的代理服务器进行全局代理选择。[C#] WebRequest req =
new WebRequest.Create(" http://www.contoso.com/"); req.Proxy = new
WebProxy(" http:// alternateproxy:80 /");



请看以下主题:
- HTTP
- 通过代理访问互联网

玩得开心!

马丁

Abubakar写道:
< blockquote class =post_quotes> hi,
我在作为网络一部分的计算机上工作,并使用代理连接到网络。我无法使用简单的ConnectTo代码连接到代理外部的服务器。我需要知道如何让我的请求通过代理。例如,
_socket = new TcpClient(" http://msdn.microsoft.com" ;, port);
不起作用。
Thanx。
Ab。



hi,
I work on a computer that is part of a network and uses proxy to connect to net. I cant connect to servers outside my proxy with simple ConnectTo code. I need to know how to make my requests go through proxy. eg,
_socket = new TcpClient("http://msdn.microsoft.com", port);
does not work.
Thanx.
Ab.

解决方案

Hi Abubakar,

I''m not good i .NET network stuff, but...
The TcpClient constructor needs a "host name"
(e.g. "msdn.microsoft.com"), not a WWW address.

Regards

Marcin

hi,
I work on a computer that is part of a network and uses proxy to connect to net. I cant connect to servers outside my proxy with simple ConnectTo code. I need to know how to make my requests go through proxy. eg,
_socket = new TcpClient("http://msdn.microsoft.com", port);
does not work.
Thanx.
Ab.



From MSDN:

If your site uses a proxy to provide access to the Internet, you must
configure a proxy instance to enable your application to communicate
with the Web proxy. The following code example creates a global proxy
instance that will enable any WebRequest to use a proxy to
communicate with the Internet. The example assumes that the proxy
server is named webproxy and that it communicates on port 80, the
standard HTTP port. [C#] WebProxy proxyObject = new WebProxy("http://webproxy:80/");
GlobalProxySelection.Select = proxyObject; You can override the global proxy selection by assigning an instance
that implements the IWebProxy interface to the Proxy property of your
WebRequest. The following code example sends a WebRequest to
www.contoso.com that overrides the global proxy selection with a
proxy server named alternateproxy on port 80. [C#] WebRequest req =
new WebRequest.Create("http://www.contoso.com/"); req.Proxy = new
WebProxy("http://alternateproxy:80/");
Look at the following topics:

- HTTP
- Accessing the Internet Through a Proxy

Have Fun!

Martin

Abubakar wrote:
hi,
I work on a computer that is part of a network and uses proxy to connect to net. I cant connect to servers outside my proxy with simple ConnectTo code. I need to know how to make my requests go through proxy. eg,
_socket = new TcpClient("http://msdn.microsoft.com", port);
does not work.
Thanx.
Ab.



I dont want to use WebRequest,,, I want to use TCPClient.

"mphanke" wrote:

From MSDN:

If your site uses a proxy to provide access to the Internet, you must
configure a proxy instance to enable your application to communicate
with the Web proxy. The following code example creates a global proxy
instance that will enable any WebRequest to use a proxy to
communicate with the Internet. The example assumes that the proxy
server is named webproxy and that it communicates on port 80, the
standard HTTP port.


[C#] WebProxy proxyObject = new WebProxy("http://webproxy:80/");
GlobalProxySelection.Select = proxyObject;


You can override the global proxy selection by assigning an instance
that implements the IWebProxy interface to the Proxy property of your
WebRequest. The following code example sends a WebRequest to
www.contoso.com that overrides the global proxy selection with a
proxy server named alternateproxy on port 80. [C#] WebRequest req =
new WebRequest.Create("http://www.contoso.com/"); req.Proxy = new
WebProxy("http://alternateproxy:80/");



Look at the following topics:

- HTTP
- Accessing the Internet Through a Proxy

Have Fun!

Martin

Abubakar wrote:

hi,
I work on a computer that is part of a network and uses proxy to connect to net. I cant connect to servers outside my proxy with simple ConnectTo code. I need to know how to make my requests go through proxy. eg,
_socket = new TcpClient("http://msdn.microsoft.com", port);
does not work.
Thanx.
Ab.



这篇关于代理上的TCPClient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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