FurqanAhmed
Programmer
I am sending XML message to a URL which is not a web service using HTTPS-POST.The URL is of servlet on remote server. The code i m using is
string strRequestUrl="<Request><Source>";
strRequestUrl+="<RequestorID Client=\"123456\" EMailAddress=\"clientName@client.co.uk\" Password=\"clientPassword\" />";
strRequestUrl+="<RequestorPreferences Language=\"en\"><RequestMode>SYNCHRONOUS</RequestMode>";
strRequestUrl+="</RequestorPreferences></Source><RequestDetails><SearchRoomTypeRequest /></RequestDetails>";
strRequestUrl+="</Request>";
string requset = "xml=" + strRequestUrl;
Uri uri = new Uri("
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(uri);
string postData = requset;
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] byte1 = encoding.GetBytes(postData);
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = "application/x-
httpWebRequest.ContentLength = postData.Length;
httpWebRequest.Timeout = 15 * 60 * 1000;
Stream newStream = httpWebRequest.GetRequestStream();
newStream.Write(byte1,0,byte1.Length);
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
httpWebRequest.Timeout = 15 * 60 * 1000;
Stream s = httpWebResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader readStream = new StreamReader( s, encode );
string sss = readStream.ReadToEnd().Replace("\n", "").Replace("\r", "").Replace("\t", "");
readStream.Close();
s.Close();
newStream.Close();
httpWebResponse.Close();
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(sss);
But when i add watch string 'sss' in watch window i see this:
"<?xml version='1.0' encoding=\"UTF-8\" ?><Response><ResponseDetails Language=\"en\"><Errors><Error><ErrorId>XML0012</ErrorId><ErrorText><![CDATA[org.xml.sax.SAXParseException: Content is not allowed in prolog.]]></ErrorText></Error></Errors></ResponseDetails></Response>"
I m not getting what is the problem. I have searched about this problem and found that because xml is not in the proper format this error occurs but i still can't figure out what is the problem with the above code. can anybody help me about this problem . Code will be appreciated.
string strRequestUrl="<Request><Source>";
strRequestUrl+="<RequestorID Client=\"123456\" EMailAddress=\"clientName@client.co.uk\" Password=\"clientPassword\" />";
strRequestUrl+="<RequestorPreferences Language=\"en\"><RequestMode>SYNCHRONOUS</RequestMode>";
strRequestUrl+="</RequestorPreferences></Source><RequestDetails><SearchRoomTypeRequest /></RequestDetails>";
strRequestUrl+="</Request>";
string requset = "xml=" + strRequestUrl;
Uri uri = new Uri("
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(uri);
string postData = requset;
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] byte1 = encoding.GetBytes(postData);
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = "application/x-
httpWebRequest.ContentLength = postData.Length;
httpWebRequest.Timeout = 15 * 60 * 1000;
Stream newStream = httpWebRequest.GetRequestStream();
newStream.Write(byte1,0,byte1.Length);
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
httpWebRequest.Timeout = 15 * 60 * 1000;
Stream s = httpWebResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader readStream = new StreamReader( s, encode );
string sss = readStream.ReadToEnd().Replace("\n", "").Replace("\r", "").Replace("\t", "");
readStream.Close();
s.Close();
newStream.Close();
httpWebResponse.Close();
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(sss);
But when i add watch string 'sss' in watch window i see this:
"<?xml version='1.0' encoding=\"UTF-8\" ?><Response><ResponseDetails Language=\"en\"><Errors><Error><ErrorId>XML0012</ErrorId><ErrorText><![CDATA[org.xml.sax.SAXParseException: Content is not allowed in prolog.]]></ErrorText></Error></Errors></ResponseDetails></Response>"
I m not getting what is the problem. I have searched about this problem and found that because xml is not in the proper format this error occurs but i still can't figure out what is the problem with the above code. can anybody help me about this problem . Code will be appreciated.