How to By Pass Proxy


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

Up Next
    Ebook Download
    View all
    Learn
    View all