Posting Special charectors using HttpWebRequest
Hi,
I am using HttpWebequest. When i post text/HTML containing special charectors like "#" , post is successfully done.
Can anybody help me?
I am using following code,
string strURL = "some text with special charectors";
HttpWebRequest HWReq = (HttpWebRequest)WebRequest.Create(strURL);
HWReq.Timeout = (int)cbTimeout.SelectedItem * 1000;
HWReq.UserAgent = "Mozilla/4.0 (compatible;MSIE 6.0b;Windows NT 5.0)";
HWReq.AllowAutoRedirect = true;
HWReq.Method = "POST";
HWReq.ContentType = "application/x-www-form-urlencoded";
HWReq.CookieContainer = new CookieContainer();
HWReq.CookieContainer.Add(ccLogin1);
HttpWebResponse HWResp = (HttpWebResponse)HWReq.GetResponse();
I am getting Error in the above last line.
Thanks,
Kiran Suthar.
Kiran SutharPosted Dec 26, 2005, 1:52 AM
AnttiPosted Dec 25, 2005, 11:56 AM
What exception message you get? You should always post the exception message, because we can't tell what the problem is without it.
If i understood right, you want a URI to have special character in it, like in GET message? For example http://www.someaddress.com/index.htm?variable=Specialchars##HERE#¤%
URI itself cannot contain special characters, but you can put special characters in get message if you convert the address this way:
string uri = "http://www.someuri.com/index.htm";string getData = "parameter=VALUE#####";
uri= Uri.EscapeUriString(uri);
getData = Uri.EscapeDataString(getData);
uri = uri + "?" + getData;
That converts URI to its escaped representation, and thus strURI is in legal URI format.