How to By Pass Proxy

// Source Code starts
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<script language="C#" runat="server">
void Page_Load(Object Src, EventArgs E) {
myPage.Text = readHtmlPage("http://www.c-sharpcorner.com");
}

private String readHtmlPage(string url)
{
String result;
WebResponse objResponse;
WebProxy proxyObject = new WebProxy("http://urproxy:port/",true);
WebRequest objRequest = System.Net.HttpWebRequest.Create(url);
objRequest.Proxy = proxyObject; 

objResponse = objRequest.GetResponse();
using (StreamReader sr = 
new StreamReader(objResponse.GetResponseStream()) )
{
result = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
}
return result;

</script>
<html>
<body>

<b>This content is being populated from a separate HTTP request to
<a href="http://www.c-sharpcorner.com">www.c-sharpcorner.com</a></b><hr/>
<asp:literal id="myPage" runat="server"/>
</body>
</html>

// Source Code End

//While Here is the Code where you need to Provide UserName,Password and //domainName if your Proxy requires these Authentication Mode.

<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<script language="C#" runat="server">
void Page_Load(Object Src, EventArgs E) {
myPage.Text = readHtmlPage("http://www.c-sharpcorner.com");
}

private String readHtmlPage(string url)
{
String result;
HttpWebRequest makeReq =(HttpWebRequest)WebRequest.Create("http://www.shivanicreations.com/");
NetworkCredential giveCred = new NetworkCredential("username","password","domain"); 
CredentialCache putCache = new CredentialCache(); 
putCache.Add(new Uri("http://www.shivanicreations.com/"), "Basic", myCred); 
makeReq.Credentials = myCache;
WebResponse objResponse;
objResponse = objRequest.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()) )
{
result = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
}
return result;

</script>
<html>
<body>
<b>The below given Page is generated from a separate Request to this URL
<a href="http://www.c-sharpcorner.com">www.c-sharpcorner.com</a></b>
<hr/>
<asp:literal id="myPage" runat="server"/>
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值