Archive

Archive for January, 2006

Passing foreign charachters in a URL

January 25, 2006 Leave a comment
If you are calling a URL, and need to pass a foreign charachter in the url (say í), you may find that the remote server doesn’t understand what you have sent. This is a trick I found to encode it properly
 

System.Web.HttpUtility.UrlEncodeUnicode(result).Replace("u00","");

 

Advertisements
Categories: Uncategorized

Getting more out of your 500 Internal Server Error

January 10, 2006 Leave a comment

When you make a request from .NET to a remote page, and that page crashes with a 500 error. the exception thrown doesn’t normally tell you anything more than a 500 server error has occurred. You can get the exact html from the page using this:

 

try

{

httpresponse = (HttpWebResponse)httprequest.GetResponse();

}

catch(Exception e)

{

if(e is WebException)

{

WebException wexError = (WebException)e;

if(wexError.Status == WebExceptionStatus.ProtocolError)

{

WebResponse wrError = wexError.Response;

Stream stmError = wrError.GetResponseStream();

StreamReader srError= new StreamReader(stmError);

string strError = srError.ReadToEnd();

System.Diagnostics.Debug.Write(strError);

throw(e);

}

}

}

 

This really helped me!

 

Also, If anyone is interested in a freelance .NET development job, please have a look at http://www.webtropy.com/articles/joboffer.asp

Categories: Uncategorized