474,052 Members | 1,437 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 12358
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
12638
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 web. I'm stumped. I looked over my code for any errors and just couldn't find what I was doing...
2
14112
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 credentials object in the context of my request, I get this error:
1
2373
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 contains the html for logon.asp (the same page that was posted to), which indicates to me that in some...
8
3968
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 contains the html for logon.asp (the same page that was posted to), which indicates to me that in some...
2
3350
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
1957
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 a race condition in the TCP handling. Since I know next to nothing about TCP, or asynchronous...
2
5694
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 initially tested it, running as a Windows Forms app on my machine (running under my network account). ...
2
3501
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 make a call to a website all subsequent attempts to use the WebService will fail with a 401...
2
8245
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 succeeds. Also, the request succeeds when forced to use Basic authentication but fails on NTLM.
0
10564
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
12179
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11625
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
12068
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
11157
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8729
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6680
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4954
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3994
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.