如何创建在C#中一个简单的代理? [英] How to create a simple proxy in C#?

查看:258
本文介绍了如何创建在C#中一个简单的代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经下载Privoxy的几个星期前,为了好玩我很好奇,想知道它的一个简单的版本可以做到的。

I have downloaded Privoxy few weeks ago and for the fun I was curious to know how a simple version of it can be done.

我知道我需要配置浏览器(客户端)请求发送到代理。代理请求发送到Web(让我们说这是一个HTTP代理)。代理将获得答案...但如何才能代理发送回请求浏览器(客户端)?

I understand that I need to configure the browser (client) to send request to the proxy. The proxy send the request to the web (let say it's a http proxy). The proxy will receive the answer... but how can the proxy send back the request to the browser (client)?

我在网上搜索C#和HTTP代理上,但还没有找到的东西,让我明白它是如何工作的幕后正确。 (我相信我不想一个反向代理,但我不知道)。

I have search on the web for C# and http proxy but haven't found something that let me understand how it works behind the scene correctly. (I believe I do not want a reverse proxy but I am not sure).

请问你们有一些解释或某些信息,这将让我继续这个小项目?

Does any of you have some explication or some information that will let me continue this small project?

这是我的理解(见下图)。

This is what I understand (see graphic below).

第1步我配置客户端(浏览器),用于将发送所有的请求到127.0.0.1在港口代理听。通过这种方式,请求将不被发送到因特网直接但会由代理来处理。

Step 1 I configure the client (browser) for all request to be send to 127.0.0.1 at the port the Proxy listen. This way, request will be not sent to the Internet directly but will be processed by the proxy.

第二步:代理看到一个新的联接,读取HTTP头,看到了要求他必须执行时。他执行的请求。

Step2 The proxy see a new connexion, read the HTTP header and see the request he must executes. He executes the request.

第三步:代理收到请求的应答。现在,他必须从网络上发送答案的客户端,但如何???

Step3 The proxy receive an answer from the request. Now he must send the answer from the web to the client but how???

颏代理的:我发现这个项目是一个代理(但更多的,我想) 。我可能会检查源,但我真的想要的东西基本了解更多的概念。

Mentalis Proxy : I have found this project that is a proxy (but more that I would like). I might check the source but I really wanted something basic to understand more the concept.

ASP代理:我也许能挺过来了一些信息太

ASP Proxy : I might be able to get some information over here too.

<一个href="http://bartdesmet.net/blogs/bart/archive/2007/02/22/httplistener-for-dummies-a-simple-http-request-reflector.aspx">Request反射:这是一个简单的例子

Request reflector : This is a simple example.

下面是一个的Git仓库中心用简单的HTTP代理

推荐答案

您可以建立一个具有<一个href="http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx"><$c$c>HttpListener类来侦听传入的请求和<一href="http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx"><$c$c>HttpWebRequest一流的中继请求。

You can build one with the HttpListener class to listen for incoming requests and the HttpWebRequest class to relay the requests.

这篇关于如何创建在C#中一个简单的代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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