Re: 500 error while GetResponse()
- From: "Kevin Spencer" <kevin@xxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 6 Sep 2005 14:47:34 -0400
Thanks Pooja,
You should be able to get more information about the error from the
WebException thrown. Here's a handy function I wrote to get the details:
public static string GetWebException(WebException ex)
{
try
{
StringBuilder sb = new
StringBuilder(ex.Response.ResponseUri.ToString());
sb.Append(Environment.NewLine + "Status: " + ex.Status.ToString());
sb.Append(Environment.NewLine + "Message: " + ex.Message);
if (ex.InnerException != null)
{
sb.Append(Environment.NewLine +
ex.InnerException.GetType().ToString());
sb.Append(Environment.NewLine +
ex.InnerException.Message);
}
return sb.ToString();
}
catch (Exception e)
{
Utilities.HandleError(e, false, "Error Getting WebException: " +
Environment.NewLine + ex.Message);
return "Error Getting WebException";
}
}
You would of course need to handle any Exception thrown by this method with
your own exception handler, rather than the one I used, which is one I
wrote. The one I wrote logs the Exception message to the Event Log, and
optionally rethrows it, as well as adding any string you want to append to
it.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
"Pooja" <Pooja@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:234F4A25-4C92-4D7B-B0B9-CC045F282A31@xxxxxxxxxxxxxxxx
> Hi Kevin,
>
> I'll try to explain it again:
>
> I have developed an ASP.Net application - www.ABC.com
>
> Now i want to develop a utility which checks whether my site is up or not.
> If it is not then i need to send an SMS alert to few people to check the
> status of the site.
>
> This utility is a console app which makes a HTTPRequest to - www.ABC.com
> So, the point at which i say - GetResponse() - i.e. when i'm trying to get
> the response of the request i made to my site, its giving me a
> System.WebException - "The remote server returned an error: (500) Internal
> Server Error."
>
> Hope i'm able to explain the problem in a better way this time.
>
> Thanks,
> Pooja.
>
> "Kevin Spencer" wrote:
>
>> > HttpWebResponse webresponse = (HttpWebResponse)wrGETURL.GetResponse();
>> >
>> > I get an error when GetResponse() is executed. The error is :
>> >
>> > "The remote server returned an error: (500) Internal Server Error."
>>
>> This question is a bit confusing. It sounds like you're saying that the
>> line
>> that executes the GetResponse method is throwing an error. However, you
>> say
>> that the error is "The remote server returned an error: (500) Internal
>> Server Error." Now, as you're developing an ASP.Net application, this
>> could
>> mean one of 2 things:
>>
>> 1. The Response contains a 500 status code.
>> 2. Your ASP.Net Page is displaying a 500 status code.
>>
>> The first would mean that the server that your WebRequest sent a Request
>> to
>> has a problem.
>> The second would mean that your ASP.Net app has a problem.
>>
>> If your app is not the one having a problem, where are you seeing this
>> error? An HttpWebResponse will contain the status code and other
>> information
>> about the success or failure of the Request. But if the problem is in
>> your
>> app, you need to be more specific about how you're getting this error
>> information.
>>
>> Can you clear this issue up?
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> ..Net Developer
>> Neither a follower nor a lender be.
>>
>> "Pooja" <Pooja@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>> news:F44641B7-19FF-4E2B-B863-14F44FC99B53@xxxxxxxxxxxxxxxx
>> > Hi All,
>> >
>> > I'm trying to make a web request to my site from some other ASP.Net
>> > Application. Code used for that is:
>> >
>> > string sURL = "<my site url>";
>> >
>> > HttpWebRequest wrGETURL = (HttpWebRequest) WebRequest.Create(new
>> > Uri(sURL));
>> >
>> > wrGETURL.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
>> > 5.0;
>> > .NET CLR 1.1.4322)";
>> >
>> > wrGETURL.AllowAutoRedirect = true;
>> > wrGETURL.CookieContainer = new CookieContainer();
>> >
>> > wrGETURL.CookieContainer.Add(new Uri(sURL), new Cookie("bhResults",
>> > "bhtz=0"));
>> >
>> > wrGETURL.CookieContainer.Add(new Uri(sURL), new Cookie("bhPrevResults",
>> > "bhtz=0"));
>> >
>> > HttpWebResponse webresponse = (HttpWebResponse)wrGETURL.GetResponse();
>> >
>> > I get an error when GetResponse() is executed. The error is :
>> >
>> > "The remote server returned an error: (500) Internal Server Error."
>> >
>> > Any ideas why i'm getting this error?
>> >
>> > Thnx in advance.
>> > Pooja.
>>
>>
>>
.
- Follow-Ups:
- Re: 500 error while GetResponse()
- From: Pooja
- Re: 500 error while GetResponse()
- References:
- 500 error while GetResponse()
- From: Pooja
- Re: 500 error while GetResponse()
- From: Kevin Spencer
- Re: 500 error while GetResponse()
- From: Pooja
- 500 error while GetResponse()
- Prev by Date: Re: Scale text according to window/screen size.
- Next by Date: Re: Datagrid using webpart in sharepoint server
- Previous by thread: Re: 500 error while GetResponse()
- Next by thread: Re: 500 error while GetResponse()
- Index(es):
Relevant Pages
|