听浏览器的请求 [英] Listen to Browser's requests
本文介绍了听浏览器的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用下面的code:
的HttpListener监听器=新的HttpListener();
//listener.$p$pfixes.Add("http://*:80/);
。监听器prefixes.Add(HTTP:// *:8080 /);
。监听器prefixes.Add(HTTP:// *:8081 /);
。监听器prefixes.Add(HTTP:// *:8082 /);
listener.Start();
HttpListenerContext上下文= listener.GetContext();
HttpListenerRequest请求= context.Request;
在的getContext()程序挂起;在IE和Firefox
尽管装载的HTTP(HTTPS不)页
当我取消的第一行出现错误:
无法对preFIX听'的http:// *:80 /,因为它与冲突 在机器上现有注册。
所以,我怎么听着浏览器的请求?
解决方案
@ L.B我想写一个代理
不要重新发明轮子,只是使用 FiddlerCore
公共类HTTPPROXY:IDisposable的
{
公共HTTPPROXY()
{
Fiddler.FiddlerApplication.BeforeRequest + = FiddlerApplication_BeforeRequest;
Fiddler.FiddlerApplication.Startup(8764,真正的,真实的);
}
无效FiddlerApplication_BeforeRequest(Fiddler.Session oSession)
{
Console.WriteLine(的String.Format(REQ:{0},oSession.url));
}
公共无效的Dispose()
{
Fiddler.FiddlerApplication.Shutdown();
}
}
修改
您可以用这个矩形轮开始:)
无效SniffPort80()
{
byte []的输入=新的字节[] {1};
Socket套接字=新的Socket(AddressFamily.InterNetwork,SocketType.Raw,ProtocolType.IP);
socket.Bind(新IPEndPoint(IPAddress.Broadcast,80));
socket.IOControl(的IOControl code.ReceiveAll,输入,NULL);
byte []的缓冲区=新的字节[0x10000的]。
Task.Factory.StartNew(()=>
{
而(真)
{
INT的len = socket.Receive(缓冲液);
如果(LEN< = 40)继续; //穷人的检查TCP有效载荷
串斌= Encoding.UTF8.GetString(缓冲,0,len个); //不要相信这种线。编码可能是不同的:)甚至可以包含如图片,视频等二进制数据
Console.WriteLine(箱);
}
});
}
Using the following code:
HttpListener listener = new HttpListener();
//listener.Prefixes.Add("http://*:80/");
listener.Prefixes.Add("http://*:8080/");
listener.Prefixes.Add("http://*:8081/");
listener.Prefixes.Add("http://*:8082/");
listener.Start();
HttpListenerContext context = listener.GetContext();
HttpListenerRequest request = context.Request;
The program hangs on the GetContext();
despite loading http (not https) pages in IE and Firefox.
When I uncomment the first line I get the error:
Failed to listen on prefix 'http://*:80/' because it conflicts with an existing registration on the machine.
So how do I listen to a browser's requests?
解决方案
@L.B I want to write a "proxy"
Don't reinvent the wheel and just use the FiddlerCore
public class HttpProxy : IDisposable
{
public HttpProxy()
{
Fiddler.FiddlerApplication.BeforeRequest += FiddlerApplication_BeforeRequest;
Fiddler.FiddlerApplication.Startup(8764, true, true);
}
void FiddlerApplication_BeforeRequest(Fiddler.Session oSession)
{
Console.WriteLine(String.Format("REQ: {0}", oSession.url));
}
public void Dispose()
{
Fiddler.FiddlerApplication.Shutdown();
}
}
EDIT
You can start with this rectangular wheel :)
void SniffPort80()
{
byte[] input = new byte[] { 1 };
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
socket.Bind(new IPEndPoint(IPAddress.Broadcast, 80));
socket.IOControl(IOControlCode.ReceiveAll, input, null);
byte[] buffer = new byte[0x10000];
Task.Factory.StartNew(() =>
{
while (true)
{
int len = socket.Receive(buffer);
if (len <= 40) continue; //Poor man's check for TCP payload
string bin = Encoding.UTF8.GetString(buffer, 0, len); //Don't trust to this line. Encoding may be different :) even it can contain binary data like images, videos etc.
Console.WriteLine(bin);
}
});
}
这篇关于听浏览器的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文