HttpWebRequest returning 504

737 views
Skip to first unread message

Scooter

unread,
May 13, 2008, 9:42:47 AM5/13/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I'm writing a simple C# app to check a list of websites every 5
minutes to see if they are up or not. I few of the sites are behind a
firewall. While I can get to them fine with my browser, wget, wfetch,
etc, when using my app I get a 504 Gateway timeout error. I can also
simply telnet to them via port 80 and get a connection. Only when
using my C# app do I get a failure. And my app, as well as the
successful hits mentioned previously were all run on the same pc, so
it shouldn't be a network issue:

I'm passing the url in as a parameter, and have printed it to debug
just to make sure its correct.

HttpWebRequest webRequest =
(HttpWebRequest)WebRequest.Create(thisURL);
webRequest.KeepAlive = false;

webRequest.Method = "GET";
try
{
webRequest.Timeout = 15000;

HttpWebResponse resp =
(HttpWebResponse)webRequest.GetResponse();
StreamReader responseReader = new
StreamReader(resp.GetResponseStream(), Encoding.UTF8);
String m_SiteData = responseReader.ReadToEnd();
resp.Close();
return m_SiteData;
}
catch (Exception ex)
{
System.Diagnostics.Debug.Print(thisURL);
System.Diagnostics.Debug.Print(ex.Message);
return "";
}


Any thoughts?

Andrew Badera

unread,
May 13, 2008, 2:15:35 PM5/13/08
to DotNetDe...@googlegroups.com
what does your network capture look like? even if it's not a "network issue" (though it probably is network-driven) the capture will tell you what exact point in the process is breaking down.
--
--
--Andy Badera
http://higherefficiency.net
http://flipbitsnotburgers.blogspot.com/
http://andrew.badera.us/
http://changeroundup.com/
and...@badera.us
(518) 641-1280
Google me: http://www.google.com/search?q=andrew+badera

AstroDrabb

unread,
May 13, 2008, 3:15:16 PM5/13/08
to DotNetDe...@googlegroups.com
Have you tried to spoof the UserAgent in your HTTP request?  It is just a string.  Google UserAgents.

A while ago, I wrote an app that would suck down mp3 files from my paid Coast to Coast AM (yeah I like it!!) account.  When I first tried the app it got rejected.  Making the code send an HTTP request as an actual know browser (I picked FF), worked like a charm.

Jim

On Tue, May 13, 2008 at 9:42 AM, Scooter <slbe...@cox.net> wrote:

Scooter

unread,
May 13, 2008, 3:55:43 PM5/13/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Thanks for the suggestion, and yes it was network-driven, so to speak.
Apparently "HttpWebReqeust" uses the IE proxy settings. If I clear my
proxy settings in IE my problem goes away.
> --Andy Baderahttp://higherefficiency.nethttp://flipbitsnotburgers.blogspot.com/http://andrew.badera.us/http://changeroundup.com/
> and...@badera.us
> (518) 641-1280
> Google me:http://www.google.com/search?q=andrew+badera- Hide quoted text -
>
> - Show quoted text -

Scooter

unread,
May 13, 2008, 4:07:22 PM5/13/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
webRequest.Proxy = null;

is my friend

Thanks

On May 13, 1:15 pm, "Andrew Badera" <and...@badera.us> wrote:
> --Andy Baderahttp://higherefficiency.nethttp://flipbitsnotburgers.blogspot.com/http://andrew.badera.us/http://changeroundup.com/
> and...@badera.us
> (518) 641-1280

Andrew Badera

unread,
May 14, 2008, 2:31:31 PM5/14/08
to DotNetDe...@googlegroups.com
Welcome, glad you got it worked out.

HttpWebRequest uses IE/Windows proxy settings by default? Interesting, I don't know that I'd ever been in a situation where I'd realized that.

Charles A. Lopez

unread,
May 16, 2008, 10:02:53 AM5/16/08
to DotNetDe...@googlegroups.com
On Tue, May 13, 2008 at 3:15 PM, AstroDrabb <astro...@gmail.com> wrote:
Have you tried to spoof the UserAgent in your HTTP request?  It is just a string.  Google UserAgents.

A while ago, I wrote an app that would suck down mp3 files from my paid Coast to Coast AM (yeah I like it!!) account.  When I first tried the app it got rejected.  Making the code
 
what's coast to coast AM?



--
Charles A. Lopez
charle...@gmail.com


Andrew Badera

unread,
May 16, 2008, 10:04:28 AM5/16/08
to DotNetDe...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages