Bob Barrows said:
Anthony,
I'm a little puzzzled here. I see from the reply that your suggestion
worked, but I'm curious as to why URL encoding is relevant with a POST.
URL encoding is relevant because the content type of the entity body is
application/x-www-form-urlencoded. Which basically uses the same
"name1=value&name2=value" method to list the field values as it would
appear in the query string, that includes any escaping you would expect in
query string had actually ben part of a URL.
Is this a peculiarity of the HTTPRequest object?
Nope it is the specification for the mime type.
If so, the OP is going to have
to worry about other characters besides "+", isn't he? He's basically going
to have to url-encode any data that he sends via this object.
Yep. I suspect that he could actually get away with just encoding &, % and
+, since other characters typically encoded by url encoding only have
special meaning when actually in a URL.
So personally I'd go with:-
CString value("^&'{}|][+\"<>\\");
value.Replace("%", "%25");
value.Replace("+", "%2B");
value.Replace("&", "%26");
pIXMLHTTPRequest->Send(value.GetString());
Another appoach is to use UrlEscape from the shlwapi.dll. It would need the
URL_ESCAPE_PERCENT flag and then you'd still need to encode the plus signs
since it doesn't do those.
I've never had to do this when using HTTPrequest, but then again, I've
always put my data into an xml document to be posted via HTTPRequest.
You would not have tried to read the XML from Request.Form but would have
read the Request entity in the raw. In the above case it is the Form object
in the Request which is parsing the entity body and doing the unescaping.
I wonder if he can avoid the url-encoding step by doing this from his C++
application ...
The question is does the receiving ASP page need to use Form fields because
it also supports POSTs from HTML forms? If so then we need to continue to
emulate the HTML Form or change how the page containing the form works.
What else is available? Sending the string raw and setting the content type
to "text/plain" is an option but ASP doesn't make retrieving a simple string
from the Request easy. You'd need to use an ADODB stream to take the the
result of BinaryRead and then return the string.
XML is my prefered option (I never use HTML Forms) and it's easy enough to
do in VB/VBScript/Javascript. Bit more of a pain in C++ if you've only got
a couple of fields to send.
Anthony.