Pure XML to an ASP page without changing the actual text?

B

Bryan Avery

I am posting XML to a ASP web page, but it is not picking up the pure XML
messages, why not?

We have to use ENCTYPE="text/plain", otherwise the XML code is changed by
Microsoft.

Here is the listening page

'Get the requesting information
XMLString = Trim(Request.Form("XML"))
If len(XMLString) = 0 Then XMLString = trim(Request.Form())
If len(XMLString) = 0 Then XMLString = trim(Request.QueryString("XML"))

Nothing is coming back when posting the following page.



Here is the post page

<form name="form1" method="post" action="ServerRequest.asp"
ENCTYPE="text/plain">
<p>
<textarea name="XML" cols="100" rows="20" id="XML">
<Server_Requests>
<Server_Request>
<Login>
<ID>10</ID>
<Password/>
</Login>
<Action>
<ActionID>2000</ActionID>
<Message>help</Message>
</Action>
</Server_Request>
</Server_Requests>

</textarea>
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
 
T

terje

| I am posting XML to a ASP web page, but it is not picking up the pure XML
| messages, why not?


Response.Write Request.Form("XML") '???
 
B

Bryan Avery

I've tried this and it does not work. Try out the code and you'll see
for yourself.
 
S

Shailesh Humbad

I believe what's going on is that the Request object does not know how
to parse the POSTed data if it's encoding type is set to text/plain.

Using analogx packetmon, here is the POSTed data normally:
---------------------------------------------------
Content-Type: application/x-www-form-urlencoded
Content-Length: 427

XMLtest=++%3CServer_Requests%3E%0D%0A++++%3CServer_Request
%3E%0D%0A+++++++%3CLogin%3E%0D%0A++++++++++%3CID%3E10%3C%2
FID%3E%0D%0A++++++++++%3CPassword%2F%3E%0D%0A+++++++%3C%2F
Login%3E%0D%0A+++++++%3CAction%3E%0D%0A++++++++++%3CAction
ID%3E2000%3C%2FActionID%3E%0D%0A++++++++++%3CMessage%3Ehel
p%3C%2FMessage%3E%0D%0A+++++++%3C%2FAction%3E%0D%0A++++%3C
%2FServer_Request%3E%0D%0A+%3C%2FServer_Requests%3E%0D%0A+
%0D%0A+&Submit=Submit
---------------------------------------------------
Note, I added the carraige returns on the XMLtest line so they
don't mess up the newsreaders.

The ASP Request object is designed to parse that kind of data.

Here is the POSTed data with text/plain encoding:
---------------------------------------------------
Content-Type: text/plain
Content-Length: 289

XMLtest= <Server_Requests>
<Server_Request>
<Login>
<ID>10</ID>
<Password/>
</Login>
<Action>
<ActionID>2000</ActionID>
<Message>help</Message>
</Action>
</Server_Request>
</Server_Requests>


Submit=Submit
---------------------------------------------------

So, I believe you will not be able to use the Request.Form collection if
you set the encoding to text/plain. What do you mean exactly when you
say the XML code is changed by Microsoft? Your page works fine for me
if I remove the ENCTYPE="text/plain" tag.

If you can work around that, then you don't have to do the following
workaround. You can read the posted data in binary, and convert it to a
string, and then parse it manually. Request.BinaryRead returns a safe
array (binary data) of the entire POSTed data. Here is at least the
first two steps, using a function copied from:
http://www.pstruh.cz/tips/detpg_binarytostring.htm

response.write "<br>total bytes: "&Request.TotalBytes
response.write "<br>whole request: "&_
Server.HTMLEncode(SimpleBinaryToString(_
Request.BinaryRead(Request.TotalBytes)))

Function SimpleBinaryToString(Binary)
'SimpleBinaryToString converts binary data
' (VT_UI1 | VT_ARRAY Or MultiByte string)
'to a string (BSTR) using MultiByte VBS functions
Dim I, S
For I = 1 To LenB(Binary)
S = S & Chr(AscB(MidB(Binary, I, 1)))
Next
SimpleBinaryToString = S
End Function
 
B

Bryan Avery

Many thanks for such a great response, it has worked a treat. Now I can
process pure XML :)
 
S

Shailesh Humbad

Which method did you use, removing the ENCTYPE tag or manually parsing
the POST data?
 
B

Bryan Avery

The complete problem is that I have different sources sending me xml and
I needed to have an ASP page to have the ability to read pure XML, one
that have not changed the source.

I have a page for testing XML to the listening XML page and that has to
use ENCTYPE of text, otherwise the texting will only test between the
two Microsoft components which is ok, but the application which is
calling the listening page in written in C++ and write out pure XML and
therefore was failing as the listening page could not read it. But now
I can decode pure text from the post message I now take the pure XML and
parse it through MSXML2.DOMDocument object.

Does this make sence?

Excuse me for asking, where are you from? I only ask as I am building a
team of good developers together to work on an exciting project and
wondered if you do any freelance work?

Many thanks for your time and support :)

<<<Bryan>>>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top