We help IT Professionals succeed at work.

How to use SERVER.URLENCODE with HTTPPOST & msxml2.serverxmlhttp

MikeCombe
MikeCombe used Ask the Experts™
on
I have 2 ASP webpages....one sends data to the other. The receving ASP webpage, "reads" the data sent & echos it back to the sending ASP webpage. I am unable to "read" the result of an HTTPPOST to my ASP webpage when using SERVER.URLENCODE. Without using server.urlencode, the code works fine.

QUESTION: How do I use server.urlencode ?

I have two test ASP webpages
test_httppost_send.asp
test_httppost_receive.asp

---------------------------------------------
test_httppost_send.asp
---------------------------------------------
       ' send data --> test_httppost_receive.asp
       color = "red"
       strMsg = "color=" & color
       myURL = "http://someurl/test_httppost_receive.asp"
       strMsg = Server.urlencode(strMsg)                       '<-- work as expected WITHOUT this line
       set xmlhttp = createobject("msxml2.serverxmlhttp")
       xmlhttp.Open "POST", myURL, false
       xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"      
       xmlhttp.Send (strMsg)
       strResponse = xmlhttp.responseText
       set xmlhttp = nothing
---------------------------------------------


---------------------------------------------
test_httppost_receive.asp
---------------------------------------------
       ' get data sent by Sender
       Sender_color = Request.Form("color")
       ' echo back                                    
       Response.Write Sender_color
---------------------------------------------






Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
If the code works fine without the Server.urlencode line, then what's the problem?  I think setting the ContentType to application/x-www-form-urlencoded takes care of the encoding anyway.

Author

Commented:
I need encoding.

If ContentType to application/x-www-form-urlencoded takes care of the encoding ...that's fine.

If not, then I have to manually do it.....and that's the line that causes the issue.....in which case I need a solution

QUESTION:
Does  -->  ContentType to application/x-www-form-urlencoded   <--  take care of the encoding ?
.
Sorry, look like setting the ContentType doesn't encode it, it just specifies that the data will be encoded.  But looking at your receive code, I think the problem is that you're looking in the Request.Form object for your variables.  You should just use Request("color") or explicitly Request.Params("color").

Author

Commented:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Sorry, look like setting the ContentType doesn't encode it, it just specifies that the data will be encoded.
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
That's what I thought.....however, I have not found anything that explictly says that.
I still do not know.


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
I think the problem is that you're looking in the Request.Form object for your variables.  You should just use Request("color") or explicitly Request.Params("color").
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
I used to think that too....I believe that Request("color")  is using the QueryString. That did not work for me. When I found Request.Form, I obtained the results I wanted.


So, now my 2 questions are:
1. Does  -->  ContentType to application/x-www-form-urlencoded   <--  take care of the encoding ?
or....do I have to encode manually (programatically, of course).
2. At the receving end, I would be getting an encoded string. How do I unencode it to parse out either Name/Value pairs or an xml document?