473,568 Members | 2,964 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HttpWebRequest and proxy issues

Hello All,
I am using HttpWebRequest to fetch webpages in my ASP.net C#
application. The request works fine without the proxy, but on using the code
from within a network that uses proxy the request does not work. I tried to
use the MS code to get around it, but having problems using it. The first
thing is that the this conversion

myProxy=(WebPro xy)myWebRequest .Proxy;

does not work, and I get an error of cannot convert Webproxywrapper to
WebProxy.
The MS code is as under.
http://msdn.microsoft.com/library/de...ProxyTopic.asp

// Create a new request to the mentioned URL.
HttpWebRequest
myWebRequest=(H ttpWebRequest)W ebRequest.Creat e("http://www.microsoft.c om");
WebProxy myProxy=new WebProxy();
// Obtain the 'Proxy' of the Default browser.
myProxy=(WebPro xy)myWebRequest .Proxy;
// Print the Proxy Url to the console.
Console.WriteLi ne("\nThe actual default Proxy settings are
{0}",myProxy.Ad dress);
try
{
Console.WriteLi ne("\nPlease enter the new Proxy Address that is to be
set:");
Console.WriteLi ne("(Example:ht tp://myproxy.com:por t)");
string proxyAddress;
proxyAddress =Console.ReadLi ne();
if(proxyAddress .Length>0)

{
Console.WriteLi ne("\nPlease enter the Credentials ");
Console.WriteLi ne("Username:") ;
string username;
username =Console.ReadLi ne();
Console.WriteLi ne("\nPassword: ");
string password;
password =Console.ReadLi ne();
// Create a new Uri object.
Uri newUri=new Uri(proxyAddres s);
// Associate the newUri object to 'myProxy' object so that new
myProxy settings can be set.
myProxy.Address =newUri;
// Create a NetworkCredenti al object and associate it with the Proxy
property of request object.
myProxy.Credent ials=new NetworkCredenti al(username,pas sword);
myWebRequest.Pr oxy=myProxy;
}
Console.WriteLi ne("\nThe Address of the new Proxy settings are
{0}",myProxy.Ad dress);
HttpWebResponse
myWebResponse=( HttpWebResponse )myWebRequest.G etResponse();
Can anyone please help me with this?
thanks a lot.
Imran.


Nov 19 '05 #1
1 12278
Imran Aziz wrote:
Hello All,
I am using HttpWebRequest to fetch webpages in my ASP.net C#
application. The request works fine without the proxy, but on using
the code from within a network that uses proxy the request does not
work. I tried to use the MS code to get around it, but having
problems using it. The first thing is that the this conversion

myProxy=(WebPro xy)myWebRequest .Proxy;

does not work, and I get an error of cannot convert Webproxywrapper
to WebProxy. The MS code is as under.
http://msdn.microsoft.com/library/de...ry/en-us/cpref
/html/frlrfSystemNetH ttpWebRequestCl assProxyTopic.a sp


That cast is wrong. HttpWebRequest. Proxy is of type IWebProxy. There's
no guarantee that the class implementing this Interface is really a
WebProxy object.

There's really no point in reading the default proxy from the
HttpWebRequest if you want to use another one. Simply create a new
WebProxy object with the desired proxy URL, set the required
credentials and assign this object to the HttpWebRequest' s Proxy
property.

Cheers,

--
http://www.joergjooss.de
mailto:ne****** **@joergjooss.d e
Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
12580
by: Jeff B | last post by:
I'm trying to create a simple screen scraping application and I kept getting a System.Net.WebException thrown back with a message of "The operation has timed-out." At first I thought it was some kind of connectivity issue on the machine. It didn't make sense though, because I can open up a browser on the same machine and easily browse the...
2
14085
by: Steve Richter | last post by:
I have a page that uses simple HTTP GET to do an ISBN lookup via Amazon.com. The page works when I run it from //localhost. But I have moved it to my godaddy.com shared hoster site, and I get errors on the HttpWebRequest.GetResponse statement. The remote server returned an error: (401) Unauthorized also, when I use the network...
1
2350
by: Dave Brown | last post by:
I am attempting to post to a url (https://FakeURL/logon.asp) using the HttpWebRequest class. The response for a succesful post will contain the html for the logon user's default page. We've accomplished this in the past utilizing the ServerXMLHTTP object. When I try an equivalent? post utilizing the HttpWebRequest class, the response...
8
3941
by: Dave Brown | last post by:
I am attempting to post to a url (https://FakeURL/logon.asp) using the HttpWebRequest class. The response for a succesful post will contain the html for the logon user's default page. We've accomplished this in the past utilizing the ServerXMLHTTP object. When I try an equivalent? post utilizing the HttpWebRequest class, the response...
2
3321
by: Tyler | last post by:
I am using httpwebrequest to do a screen scrape. This works great on my development box, but does not on the production box. Here is the code. Dim webRequest As HttpWebRequest = CType(webRequest.Create(LOGIN_URL), HttpWebRequest) webRequest.Proxy = System.Net.GlobalProxySelection.GetEmptyWebProxy webRequest.KeepAlive = False
2
1932
by: =?Utf-8?B?SmV0dCBKb25lcw==?= | last post by:
I'm working on a webdav client which makes multiple webrequests using the threadpool. The initial issue was that some requests never returned, though I could attach to the application and see they were still blocked at webReq.GetResponse(). I finally fired up netmon to see where the connection seemed to be getting lost, and it seems to be...
2
5673
by: =?Utf-8?B?U2ltb25EZXY=?= | last post by:
Hi I have a utility class, called MailHandler, that I wrote to read and operate on emails on an Exchange server using WebDAV. The WebDAV SQL statements are sent using an HttpWebRequest object. This worked fine in a .NET 1.1 project. I have copied the same Mailhandler class into a .NET 2.0 project. This, too, worked fine when I...
2
3472
by: =?Utf-8?B?TGFycnlLdXBlcm1hbg==?= | last post by:
Our WebDev team seems to have found a problem that exposes a bug in .NET 2.0. This problem can be shown when trying to access a WebService using SSL and through a proxy server after using the HttpWebRequest object. Under normal circumstances I am able to use the webservice without any problems. But after using an HttpWebRequest object to...
2
8146
by: =?Utf-8?B?TGVuc3Rlcg==?= | last post by:
A C# (.NET 2) application which uses the System.Net.HttpWebRequest object to request a resource over HTTPS is failing following the installation of a new proxy server on our internal network with 407 Proxy Authentication Required. The same request through the old proxy succeeds. The same request to an HTTP address through the new proxy...
0
7693
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8117
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6275
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5498
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
932
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.