ARTICLE

How to By Pass Proxy

Posted by Shivani Articles | Internet & Web September 10, 2001
There are many like me who are behind the Proxy and many time you are not able to use the recent Data in your Program from Web as your are not able to retrieve that data because of Proxy coming in between.
Reader Level:

Description 

There are many like me who are behind the Proxy and many time you are not able to use the recent Data in your Program from Web as your are not able to retrieve that data because of Proxy coming in between. As finally here is the solution for all those Web Savvy Programmers to byPass Proxy.

There are two Code mentioned here first in which you only need to byPass Proxy and no Authentication Required.

Source Code:

// 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>

bye,

Shivani~~~

Article Extensions
Contents added by ezzat askari on Mar 07, 2010
COMMENT USING

Trending up