Problem with external URL
-
Hello, In my application, I have the need to test (only test) if a given web address (www.microsoft.com for example) that is provided by my application’s user is a valid url or not. So I tried to reach that external web page from my asp.net web page and I implemented this method: public static bool HttpTestUrl(string url) { bool bResult = true; if(url.StartsWith("/")) url = "http://" + getCurrentHost() + url; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); } catch(System.Net.WebException) { bResult = false; } return bResult; } And here is the result I got: For web address that are in my localhost, it works fine, but with external web address (url like www.microsoft.com for example) it generates an exception. I think I must provide my proxy parameters to the webrequest (I am using a proxy for internet connection) so please tell how to do that and what to add. I am using v1 of the framework. Thanks in advance.
-
Hello, In my application, I have the need to test (only test) if a given web address (www.microsoft.com for example) that is provided by my application’s user is a valid url or not. So I tried to reach that external web page from my asp.net web page and I implemented this method: public static bool HttpTestUrl(string url) { bool bResult = true; if(url.StartsWith("/")) url = "http://" + getCurrentHost() + url; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); } catch(System.Net.WebException) { bResult = false; } return bResult; } And here is the result I got: For web address that are in my localhost, it works fine, but with external web address (url like www.microsoft.com for example) it generates an exception. I think I must provide my proxy parameters to the webrequest (I am using a proxy for internet connection) so please tell how to do that and what to add. I am using v1 of the framework. Thanks in advance.
You might want to look at this[^] about a probloem while using HttpWebRequest in an ASP.NET page. As for the proxy, did you see, in Intellisense, that HttpWebRequest has a
.Proxy
property? You can learn more about that here[^]. By default, a WebRequest is created using the default browser proxy settings. If IE (on your IIS server!) doesn't have a proxy configuration, you'll have to specify one in your code.HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
Uri newUri = new Uri(@"proxyAddressAsString");
WebProxy myProxy = new WebProxy();
myProxy.Address = newUri;
myProxy.Credentials = new NetworkCredential(@"username",@"password");
request.Proxy = myProxy;RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome