httpwebrequest problems

G

Guest

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
Dim responseReader As StreamReader = New
StreamReader(webRequest.GetResponse.GetResponseStream)
Dim responseData As String = responseReader.ReadToEnd
responseReader.Close()

On my production box, I get this error:
The underlying connection was closed. Unable to connect to the remote server.

I have made sure I have .NET framework 1.1 SP 1 installed

I have added the following code to my web.config file

<system.net>
<defaultProxy>
<proxy
usesystemdefault = "false"
proxyaddress="http://proxy:port"
bypassonlocal="false"
/>
</defaultProxy>
</system.net>

And now I am at a loss?

Any thoughts?
Thanks
 
G

Guest

Um,
don't you want GetDefaultProxy, not
webRequest.Proxy = System.Net.GlobalProxySelection.GetEmptyWebProxy

Its' DefaultProxy that you show in your config. You can also try more
specific code like this:



if (ConfigurationSettings.AppSettings["proxy"] != null)
{
WebProxy p = null;
string proxyAddressAndPort =
ConfigurationSettings.AppSettings["proxy"];
string proxyUserName =
ConfigurationSettings.AppSettings["proxyUserName"];
string proxyPassword =
ConfigurationSettings.AppSettings["proxyPassword"];
ICredentials cred;
cred = new NetworkCredential(proxyUserName, proxyPassword);
p = new WebProxy(proxyAddressAndPort, true, null, cred);
GlobalProxySelection.Select = p;
}


Peter
 
G

Guest

Thanks for your response Peter. I tried both suggestions with the same
result. This one has me baffled. I can type the url into a browser on the
production box and it will pull up the site just fine. And again, it works
on my development box, but not the production box.
--
Tyler


Peter Bromberg said:
Um,
don't you want GetDefaultProxy, not
webRequest.Proxy = System.Net.GlobalProxySelection.GetEmptyWebProxy

Its' DefaultProxy that you show in your config. You can also try more
specific code like this:



if (ConfigurationSettings.AppSettings["proxy"] != null)
{
WebProxy p = null;
string proxyAddressAndPort =
ConfigurationSettings.AppSettings["proxy"];
string proxyUserName =
ConfigurationSettings.AppSettings["proxyUserName"];
string proxyPassword =
ConfigurationSettings.AppSettings["proxyPassword"];
ICredentials cred;
cred = new NetworkCredential(proxyUserName, proxyPassword);
p = new WebProxy(proxyAddressAndPort, true, null, cred);
GlobalProxySelection.Select = p;
}


Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Tyler said:
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
Dim responseReader As StreamReader = New
StreamReader(webRequest.GetResponse.GetResponseStream)
Dim responseData As String = responseReader.ReadToEnd
responseReader.Close()

On my production box, I get this error:
The underlying connection was closed. Unable to connect to the remote server.

I have made sure I have .NET framework 1.1 SP 1 installed

I have added the following code to my web.config file

<system.net>
<defaultProxy>
<proxy
usesystemdefault = "false"
proxyaddress="http://proxy:port"
bypassonlocal="false"
/>
</defaultProxy>
</system.net>

And now I am at a loss?

Any thoughts?
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,237
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top