前几天有个小项目需要仿某个网站!网站用有js脚本检测!会挑战到指定网页,用离线下载器无法下载!首先 想到的是再http协议中做手脚!
通过http代理 再http代理服务器做出相应的时候!篡改污染掉html.然后试试下载!废话不多说直接上代码!
用到c#开源程序
https://github.com/justcoding121/Titanium-Web-Proxy
这个东西可以实现代理http 大家可以自己下载最新版本
public void OnResponse(object sender, SessionEventArgs e)
{
read response headershttp://www.00853f.com/
var responseHeaders = e.ProxySession.Response.ResponseHeaders;
if (!e.ProxySession.Request.Hostname.Equals("www.***.com")) return;
if (e.RequestMethod == "GET" || e.RequestMethod == "POST")
{
if (e.ProxySession.Response.ResponseStatusCode == "200")
{
if (e.ProxySession.Response.ContentType.Trim().ToLower().Contains("text/html"))
{
string coding= e.GetResponseBodyEncoding().ToString();
//byte[] responseBodyBytes = e.GetResponseBody();
//e.SetResponseBody(responseBodyBytes);
//Get response body as string
string responseBody = e.GetResponseBodyAsString();
string modified = responseBody.Replace("self == top", "1==0");
//Set modifed response Html Body
e.SetResponseBodyString(modified);
}
}
}
这个是服务端响应事件!这里拦截到www.***.com域名然后替换了其中的文本!
然后是用代理服务器下载这个网站!非常不错!全部网页中检查代码被我干掉!再也不会干扰了!
利用该工具还可以污染html 加入广告等! 篡改html 就写到这里!欢迎大家提问!C#技术交流群:179536874