IIS ASP - Msxml2.ServerXMLHTTP.4.0 + &

This is Interesting: Free IT Magazines  
Home > Archive > IIS ASP > June 2004 > Msxml2.ServerXMLHTTP.4.0 + &





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Msxml2.ServerXMLHTTP.4.0 + &
ashton

2004-06-30, 6:01 pm

Hello,

I have a process that has been sending an xml file to a different web server using Msxml2.ServerXMLHTTP.4.0 and I just recently came into a problem.

This is how it works:
password=Request.Form("password")
password=Request.Form("password")
xmlData = Request.Form("xmlData")
Set xmlConnection = Server.CreateObject("Msxml2.ServerXMLHTTP.4.0")
xmlConnection.Open "POST", sendServer, False
xmlConnection.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlConnection.Send "username="+username+"&username="+username+"&xml="+xmlData

This works just fine until the xml has an & sign in it, from what I gather when I type this line:
xmlConnection.Send "username="+username+"&username="+username+"&xml="+xmlData

The & character in the xml breaks the xml variable apart. If my xml looked like this <basic>george & wallace</basic>
The url string would look like this:

server?username=user&password=pass&xml=<basic>george & wallace</basic>

so the server would receive the following variables:
username=user
password=password
xml = <basic>george
wallace=</basic>

Does this make sense? Is there a way I can get around this?
Chris Barber

2004-06-30, 6:01 pm

You have to encode the ampersand as & or use the unicode number (0026 - not sure about the
actual format for this) or the numeric format & (which I prefer).

The obvious problem is handling how this is output to the resultant XML / HTML / text when using an
XSL transform - a big topic.

Note that when DOM methods are used to put the value into an XML document then the XML parser
automagically puts the encoded version on for you - getting it out again is another matter entirely.

Chris.

"ashton" <ashton@discussions.microsoft.com> wrote in message
news:8A350E6A-F75C-4594-A54A-E613D8D3FC9A@microsoft.com...
Hello,

I have a process that has been sending an xml file to a different web server using
Msxml2.ServerXMLHTTP.4.0 and I just recently came into a problem.

This is how it works:
password=Request.Form("password")
password=Request.Form("password")
xmlData = Request.Form("xmlData")
Set xmlConnection = Server.CreateObject("Msxml2.ServerXMLHTTP.4.0")
xmlConnection.Open "POST", sendServer, False
xmlConnection.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlConnection.Send "username="+username+"&username="+username+"&xml="+xmlData

This works just fine until the xml has an & sign in it, from what I gather when I type this line:
xmlConnection.Send "username="+username+"&username="+username+"&xml="+xmlData

The & character in the xml breaks the xml variable apart. If my xml looked like this <basic>george &
wallace</basic>
The url string would look like this:

server?username=user&password=pass&xml=<basic>george & wallace</basic>

so the server would receive the following variables:
username=user
password=password
xml = <basic>george
wallace=</basic>

Does this make sense? Is there a way I can get around this?


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.712 / Virus Database: 468 - Release Date: 27/06/2004


ashton

2004-06-30, 6:01 pm

Hi Chris, thanks for the reply.

Let me try to rephrase my question.

I am trying to send 3 variables using Msxml2.ServerXMLHTTP.4.0

The first variable is the username, the second the password, and the last variable is a block of xml.

This process has been working fine, until I came across the & symbol.

I have many different systems running that are translating xml, so whenever I have this problem it is just a matter of changing the character from & to & (I'm not sure how this formatting will display in the newsgroups so I format the & sign to & a m
p ;)

This usually does the trick. In this case it does not seem to have any effect and I still get an error from the web site I post the xml to. The error always says the same thing; there is a problem with line X (where X is the line with the & symbol).

From what I have gathered the problem isn't how I am sending the & character, because I know I am sending it properly formatted. But from the way Msxml2 posts my information.

This line:

xmlConnection.Send "user="+username+"&pass="+password+"&xml="+xmlData

In this line I am just connecting strings together. Could this be the problem?

Let's say my "username" variable was joe&bard

That line above would translate to:

xmlConnection.Send "user=joe&bard"&pass="+password+"&xml="+xmlData

And if my password value was pass2, and the xmlData was <xml></xml>

It would be fully translated as:

xmlConnection.Send "user=joe&bard&pass=pass2&xml=<xml></xml>"

So when the web server on the other side tries to get the value of "user" they would only get "bard" as a response. Correct?

Even if the & sign was changed to & It would look like this:

xmlConnection.Send "user=joe&bard&pass=pass2&xml=<xml></xml>"
or (depending on newsgroup formatting)
xmlConnection.Send "user=joe&amp;bard&pass=pass2&xml=<xml></xml>"

And (in either example) when the person requested the value of "user" they would still only get "joe". That's because the & sign is forcing that variable to end.

The same with the xml, the & sign, no matter if it is formatted or not (&, &, &) is forcing that variable to end.

This is what I am thinking is happening to my xml when I send it. What I need to know is if there is a way to rewrite my xmlConnection.Send line so it does not have all of the variables concatenated on a single string. Or a way to eliminate this ampersand
problem?

Mark Schupp

2004-06-30, 6:01 pm

xmlConnection.Send "user="+username+"&pass="+password+"&xml="+
server.URLEncode(xmlData)


--
Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com


"ashton" <ashton@discussions.microsoft.com> wrote in message
news:3440D147-9C1F-4E97-A173-F40AC252623B@microsoft.com...
> Hi Chris, thanks for the reply.
>
> Let me try to rephrase my question.
>
> I am trying to send 3 variables using Msxml2.ServerXMLHTTP.4.0
>
> The first variable is the username, the second the password, and the last

variable is a block of xml.
>
> This process has been working fine, until I came across the & symbol.
>
> I have many different systems running that are translating xml, so

whenever I have this problem it is just a matter of changing the character
from & to & (I'm not sure how this formatting will display in the
newsgroups so I format the & sign to & a m p ;)
>
> This usually does the trick. In this case it does not seem to have any

effect and I still get an error from the web site I post the xml to. The
error always says the same thing; there is a problem with line X (where X is
the line with the & symbol).
>
> From what I have gathered the problem isn't how I am sending the &

character, because I know I am sending it properly formatted. But from the
way Msxml2 posts my information.
>
> This line:
>
> xmlConnection.Send "user="+username+"&pass="+password+"&xml="+xmlData
>
> In this line I am just connecting strings together. Could this be the

problem?
>
> Let's say my "username" variable was joe&bard
>
> That line above would translate to:
>
> xmlConnection.Send "user=joe&bard"&pass="+password+"&xml="+xmlData
>
> And if my password value was pass2, and the xmlData was <xml></xml>
>
> It would be fully translated as:
>
> xmlConnection.Send "user=joe&bard&pass=pass2&xml=<xml></xml>"
>
> So when the web server on the other side tries to get the value of "user"

they would only get "bard" as a response. Correct?
>
> Even if the & sign was changed to & It would look like this:
>
> xmlConnection.Send "user=joe&bard&pass=pass2&xml=<xml></xml>"
> or (depending on newsgroup formatting)
> xmlConnection.Send "user=joe&amp;bard&pass=pass2&xml=<xml></xml>"
>
> And (in either example) when the person requested the value of "user" they

would still only get "joe". That's because the & sign is forcing that
variable to end.
>
> The same with the xml, the & sign, no matter if it is formatted or not (&,

&, &) is forcing that variable to end.
>
> This is what I am thinking is happening to my xml when I send it. What I

need to know is if there is a way to rewrite my xmlConnection.Send line so
it does not have all of the variables concatenated on a single string. Or a
way to eliminate this ampersand problem?
>



ashton

2004-06-30, 6:01 pm

Thanks!
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com