1
Reply

HttpWebRequest and HttpWebResponse fails to send and recieve xml

Pearl A

Pearl A

Jun 4 2009 6:33 AM
33.8k

Hi,
I am trying to send an XML via POST to a website (gaming website) whose client UI is a flash player. Instead of sending the POST message from flash player, I worte a small code snippet. I get an exception when i hit this code: xmldoc.Load(objXMLReader);. The error says: "An error occurred while parsing EntityName. Line 58, position 84". Kindly help what went wrong in the code.
The complete code is mentioned below.
XmlDocument XMLResponse = null;
HttpWebRequest objHttpWebRequest;
HttpWebResponse objHttpWebResponse = null;
Stream objRequestStream = null;
Stream objResponseStream = null;
XmlTextReader objXMLReader;
string v_strURL = @"https://www.bluesq.com/secure/bsqgames?action=GoPreloader&cgr_id=11509&cgf_id=11510&ext_game=Y&flash_login=Y&flash_cust=NTMedia&free_play=Y&width=765&height=560";
objHttpWebRequest = (
HttpWebRequest)WebRequest.Create(v_strURL);
byte[] bytes;
XmlDocument v_objXMLDoc = new XmlDocument();
v_objXMLDoc.LoadXml(
@"<GameRequest><Header><ClientDetails id=""game:Game Version G_PKG15_CARIBBEANNIGHTS20E4APROG_18, topbar:G_PKG15_TOPBARSF8_66, preloader:G_PKG15_PRELOADERF8_34"" type="""" /><GameDetails class=""Slot"" name=""FreeCaribbeanNights20E4aProg"" free_play=""Yes"" channel=""Z"" /><Customer cookie=""BSQ_Login=IZD794q7wKwhSqrWrA==; AFF_ID=10000; FLAGS=bluesquare; IBSXLLANG=en; VIEW_ID=default; AFF_ID=10000; PRICE_TYPE=ODDS; BSQ_menu_item=; BSQ_sub_menu_item=; BSQ_Login_INSECURE=; bluesquare=203.78.214.163.1244012552370671; usy46gabsosd=bluesqcsa__1690241_3307; bluesqcsaDBID=0; bluesqcsauvt=1690241_1244012586398_1690241_1244012586398_1; fpc10001363577302=ybXS0Mkg|vCQQHjuJaa|fses10001363577302=|vCQQHjuJaa|ybXS0Mkg|fvis10001363577302=Zj1odHRwJTNBLy93d3cuYmx1ZXNxLmNvbS9iZXQmYj1TcG9ydHMlMjBCZXR0aW5nJTIwLSUyME9ubGluZSUyMEJldHRpbmclMjBhdCUyMEJsdWUlMjBTcXVhcmU=|8sTTY8s1o7|8sTTY8s1o7|8sTTY8s1o7|8|8sTTY8s1o7|8sTTY8s1o7"" is_guest=""Yes"" balance=""96200"" affiliate="""" /></Header><Play stake=""14.00"" stake_per_line=""1.00"" freebets=""No"" sequence_no=""0""><SlotState action=""spinReels"" sel_win_lines=""0|1|2|3|4|5|6|7|8|9|10|11|12|13"" reverse_payout=""No"" delim=""|"" /></Play></GameRequest>");
bytes = System.Text.
Encoding.ASCII.GetBytes(v_objXMLDoc.InnerXml);
objHttpWebRequest.Method =
"POST";
objHttpWebRequest.Accept =
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
objHttpWebRequest.KeepAlive =
true;
objHttpWebRequest.Referer =
@"https://www.bluesq.com/secure/bsq_ent/swf_OrbisTopbar/Preloaders/BSQGames-Preloader.swf";
objHttpWebRequest.ContentLength = bytes.Length;
objHttpWebRequest.ContentType =
"application/x-www-form-urlencoded; text/xml; encoding='utf-8'";
objRequestStream = objHttpWebRequest.GetRequestStream();
objRequestStream.Write(bytes, 0, bytes.Length);
objRequestStream.Close();
objHttpWebResponse = (
HttpWebResponse)objHttpWebRequest.GetResponse();
if (objHttpWebResponse.StatusCode == HttpStatusCode.OK)
{
objResponseStream = objHttpWebResponse.GetResponseStream();
objXMLReader =
new XmlTextReader(objResponseStream);
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(objXMLReader);
XMLResponse = xmldoc;
objXMLReader.Close();
}

Answers (1)