如何在c ++ / cli中重定向url [英] how to redirect url in c++/cli

查看:74
本文介绍了如何在c ++ / cli中重定向url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个小应用程序,当我的应用程序在该PC上运行时,将特定URL重定向到另一个URL ...

例如

如果我键入http: //www.yahoo.com

然后浏览器应该转到http://www.google.com。

i找到很多,但没有得到适当的答案。

vc ++。net和vc ++欢迎两种建议......

i want to make small application that will redirect the particular url to another url when my application is running on that pc..
e.g
if i type http://www.yahoo.com
then browser should go to http://www.google.com.
i find a lot but didn't get appropriate answer.
vc++.net and vc++ both suggetion are welcome...

推荐答案

查看此链接

http://stackoverflow.com/questions/2214053/c-redirect-outgoing-connections [ ^ ]


我猜你已经拥有被阻止网站的列表,你正在编写阻止他们的代码并重定向到你的默认重定向网站..



这是一个非常基本的功能一个标准的防火墙...



好​​好阻止或允许从浏览器请求的任何站点,你必须捕获这些请求并采取行动......我认为你已经为此编写了代码,它实际上是一个防火墙程序。 (如果您在编写防火墙时遇到问题,请问我)



对于重定向,HTTP规范中有一个名为LOCATION的HEADER,您需要通过所需的重定向来设置此标头您的回复中的网站如www.codeproject.com。



否则您可以使用元重定向。 (这是更容易的方式...)







< title>您的页面标题





此处可选页面文字。

此网站被阻止,您将重定向到codeproject.com









这里5表示你想在重定向之前等待多少秒,同时你可以显示一条消息,这个网站被阻止,你被重定向到codeproject.com





好​​运眨眼| ; - )
I guess you already have that list of blocked sites and you are writing code for block them and redirect to your default redirecting site..

It is a very basic functionality of a standard firewall...

Well for blocking or allowing any site requested from the browser you must capture those request and take action... and i think you already wrote the code for this, it is a firewall program actually. (If you are having problem in writing firewall then ask me)

For redirection there is a HEADER in HTTP specification called LOCATION you need to set this header by your desired redirecting site like "www.codeproject.com" in your response.

Otherwise you can use meta redirect. (Which is easier way...)



<title>Your Page Title


Optional page text here.
this site is blocked and you are redirection to codeproject.com




Here 5 indicates how many seconds you want to wait before redirect, meanwhile you can show a message that, this site is blocked and you are redirection to codeproject.com


Good Luck Wink | ;-)


确定所有你需要的 -

1.配置网络浏览器以通过你的程序连接互联网。如果你使用的是Internet Explorer,那么转到工具互联网选项连接局域网设置检查使用局域网的代理并放置127.0.0.1;代替地址:和8080(或任何你想要的)作为端口号。之后点击在任何链接或转到任何地址,然后您的浏览器将尝试在IP上建立连接:您配置的端口。

2.创建服务器套接字并开始侦听端口8080(或您配置的任何内容)接受来自Web浏览器的连接并从客户端套接字读取所有数据(这是Web浏览器发送的数据),现在您有一个HTTP请求。读取这个4k缓冲区就足够了。

3.现在解析此请求并获取HOST:header的值,它必须看起来像Host:www.google.co.in(读取HTTP请求格式的HTTP规范)。提示解析它查找索引; host:或主机:或主机:并从主机开始复制数据:直到\\\\ n。修剪内容。

现在你得到了所需的主机名。

4.现在你有2个案例

A.这个主机名是在您的阻止列表中。

怎么办: - 将这些行放入缓冲区



Ok all you need-
1. Configure web browser to connect internet through your program. If you are using internet explorer then Goto tools internet option Connection LAN setting check "use a proxy for your LAN and put 127.0.0.1; in place of Address: and 8080 (or whatever you want) as port no. After this when you click on any link or go to any address then your browser will attempt to make a connect on IP:PORT you configured.
2. Create a server socket and start listening on port 8080 (or what ever you configured). Accept connect from web browser and read all data from client socket (It is data sent by web browser), now you have a HTTP request. for reading this 4k buffer is sufficient.
3. Now parse this request and get the value of HOST: header it must look like "Host: www.google.co.in" (read HTTP specification for the HTTP request format). Hint for parse it look for the index of ;host:" or "Host:" or "HOST:" and copy data starting from Host: and till the "\r\n". Trim the content.
And now you got the desired host name.
4. Now you have 2 cases
A. This host name is in your block list.
What to do :-Take these lines into a buffer

<html><br />
<head><br />
<title>Your Page Title</title><br />
<meta http-equiv="REFRESH" content="5;url=http://www.codeproject.com"></meta></head><br />
<body><br />
Optional page text here.<br />
This site is blocked and you are redirecting to<br />
www.codeproject.com in 5 seconds<br />
</body><br />
</html>





并将该缓冲区写入客户端套接字(浏览器的插座)。现在浏览器会在5秒内将页面重定向到www.codeproject.com。



B.这个主机名在你的阻止列表中。

怎么做: - 创建一个客户端TCP套接字连接到刚刚解析的主机,向它写入HTTP请求并读取响应。现在将此响应写入网页浏览器的套接字,浏览器将呈现页面。







如果您发现任何难以理解或实施它随意询问,一旦您编写基本程序,我会告诉您一些与设计相关的优化



and write that buffer to the client socket (socket for browser). Now browser will redirect page to www.codeproject.com in 5 seconds.

B. This host name is in your block list.
What to do :- create a client TCP socket connect to the host which you just parsed write the HTTP request to it and read the response. now write this response to the socket for web browser and browser will render the page.



If you found any difficulty to understand or implement it feel free to ask and once you write basic program then i will tell you about some design related optimization


这篇关于如何在c ++ / cli中重定向url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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