EDN Admin
Well-known member
Hello,
I want to read xml string that is returned from an url https://something.aspx in C# using httpwebresponse,but I got the same error again again :
Expected DTD markup was not found. Line 1, position 3.
the content type of response is text/html,I just want to read xml string.
The same thing I have done in html 5 mobile app using AJAx but getting problem when doing with C# for desktop application.
Here is my code snippet.
HttpWebRequest req = WebRequest.Create(new Uri("https:/som
ething.aspx")) as HttpWebRequest;
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
XmlTextReader objXMLReader;
XmlDocument XMLResponse = null;
StringBuilder paramz = new StringBuilder();
paramz.Append("&RequestType=GetDetails");
paramz.Append("&UserID=1234");
paramz.Append("&Password=1234");
paramz.Append("&Name=" +test);
Uri.EscapeUriString(paramz.ToString());
// Encode the parameters as form data:
byte[] formData = UTF8Encoding.UTF8.GetBytes(paramz.ToString());
req.ContentLength = formData.Length;
// Send the request:
using (Stream post = req.GetRequestStream())
{
post.Write(formData, 0, formData.Length);
}
string result = null;
using (HttpWebResponse resp = req.GetResponse()
as HttpWebResponse)
{
if (resp.StatusCode == HttpStatusCode.OK)
{
//Success event handler
StreamReader reader = new StreamReader(resp.GetResponseStream());
objXMLReader = new XmlTextReader(reader);
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(objXMLReader); ----> throwing error.
//Set XMLResponse object returned from XMLReader
XMLResponse = xmldoc;
//Close XMLReader
objXMLReader.Close();
}
}
MessageBox.Show(result, "Result of Web Response XML");
} I received xml string as response in mobile app using AJAX.
Any help would be greatly appreciated.
Suraj
View the full article
I want to read xml string that is returned from an url https://something.aspx in C# using httpwebresponse,but I got the same error again again :
Expected DTD markup was not found. Line 1, position 3.
the content type of response is text/html,I just want to read xml string.
The same thing I have done in html 5 mobile app using AJAx but getting problem when doing with C# for desktop application.
Here is my code snippet.
HttpWebRequest req = WebRequest.Create(new Uri("https:/som
ething.aspx")) as HttpWebRequest;
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
XmlTextReader objXMLReader;
XmlDocument XMLResponse = null;
StringBuilder paramz = new StringBuilder();
paramz.Append("&RequestType=GetDetails");
paramz.Append("&UserID=1234");
paramz.Append("&Password=1234");
paramz.Append("&Name=" +test);
Uri.EscapeUriString(paramz.ToString());
// Encode the parameters as form data:
byte[] formData = UTF8Encoding.UTF8.GetBytes(paramz.ToString());
req.ContentLength = formData.Length;
// Send the request:
using (Stream post = req.GetRequestStream())
{
post.Write(formData, 0, formData.Length);
}
string result = null;
using (HttpWebResponse resp = req.GetResponse()
as HttpWebResponse)
{
if (resp.StatusCode == HttpStatusCode.OK)
{
//Success event handler
StreamReader reader = new StreamReader(resp.GetResponseStream());
objXMLReader = new XmlTextReader(reader);
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(objXMLReader); ----> throwing error.
//Set XMLResponse object returned from XMLReader
XMLResponse = xmldoc;
//Close XMLReader
objXMLReader.Close();
}
}
MessageBox.Show(result, "Result of Web Response XML");
} I received xml string as response in mobile app using AJAX.
Any help would be greatly appreciated.
Suraj
View the full article