Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Receving org.xml.sax.SAXParseException: Content is not allowed in prol

Status
Not open for further replies.

FurqanAhmed

Programmer
Oct 1, 2001
87
PK
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.
 
your xml data seems to be missing the xml header
[tt]<?xml version='1.0' encoding=\"UTF-8\" ?>[/tt].

could that be it?

mr s. <;)

 
sorry, you asked for code. replace the line:

Code:
string strRequestUrl="<Request><Source>";

with this one:

Code:
string strRequestUrl="<?xml version='1.0' encoding=\"UTF-8\" ?><Request><Source>";

hope this helps,

mr s. <;)

 
Thanks for the help guys. I changed the

string requset = "xml=" + strRequestUrl;


to

string request = strRequestUrl;

only removed the "xml=" part of the string.

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top