Problem with Microsoft.XMLHTTP POST operations


I have the following function that works great when operation = GET.  If operation = POST then the send function returns an exception "parameter is incorrect".  I've tried troubleshooting but nothing seems to want to work.  Help!

function  doXMLHTTPPost(url, xmlBody: string; operation: string): string;
  vHttp     : OleVariant;
  vHttp := CreateOleObject('Microsoft.XMLHTTP'); { Requires IE5 }, url, false, EmptyParam,EmptyParam);


  result := vHttp.responseText;

Who is Participating?
Wim ten BrinkConnect With a Mentor Self-employed developerCommented:
Darn, you answered it yourself... :-)
Well, the XMLHTTP and the MSXML libraries of Windows are unicode by default so for EVERY function you have to use WideString types and not regular string types. It's a bit of a pain, though. So use: function  doXMLHTTPPost(url, xmlBody: WIDESTRING; operation: WIDESTRING): string;

I agree that the TXMLDocument class is just too heavy to use comfortably but I do wonder why you're using late binding to access the XMLHTTP library. Why not import the type library in Delphi (without the component wrapper) and then use early binding? It will improve performance quite a bit too!
rdytmireAuthor Commented:
You'll notice that the link you provided refers to the msXML component not the msXMLHTTP component.  I am not mixing DOM components, I am not passing a DOM XML structure between processes and it's the SEND method, not the OPEN method that is throwing the exception.  So your link does not provide me with an answer.

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

How does your xmlBody looks like?
rdytmireAuthor Commented:
I found the problem.  The declaration of xmlBody: string; was the issue.  the following line of code fixed the issue.


It seems I needed to convert the type of string before making the oleCall.
Maybe you are building the string as String:

'<OBJECT>' + ...something... + '</OBJECT>'

If you are building it using XMLDocument you won't have "Invalid parameter". In your way you may experience problebs with special characters like < & >, etc.
rdytmireAuthor Commented:
XMLDocument is a very heavy-weight object and I try to avoid it whenever possible.  I currently use TNavitveXML for most of my XML needs.  The string in question IS being built in the manner you describe but I am aware of the escape characters and they do not introduce errors.  It really was just as simple as properly typecasting my response.
rdytmireAuthor Commented:

This was just a test-harness to make sure our theory will work correctly.  I'll clean up stuff in the final code.
rdytmireAuthor Commented:
As an aside for future readers:  We ended up going back to the idHTTP component and using it's POST method.  IE dependency just scared us too much.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.