Solved

Problem with Microsoft.XMLHTTP POST operations

Posted on 2006-11-03
9
682 Views
Last Modified: 2008-03-03
Hi,

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;
var
  vHttp     : OleVariant;
begin
  vHttp := CreateOleObject('Microsoft.XMLHTTP'); { Requires IE5 }
  vHttp.open(operation, url, false, EmptyParam,EmptyParam);

  vHttp.send(xmlBody);

  result := vHttp.responseText;

end;
0
Comment
Question by:rdytmire
  • 5
  • 3
9 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 17871285
0
 
LVL 1

Author Comment

by:rdytmire
ID: 17872809
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.

0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 17872835
How does your xmlBody looks like?
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 1

Author Comment

by:rdytmire
ID: 17881061
I found the problem.  The declaration of xmlBody: string; was the issue.  the following line of code fixed the issue.

vHttp.send(WideString(xmlBody));


It seems I needed to convert the type of string before making the oleCall.
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 17881181
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.
0
 
LVL 1

Author Comment

by:rdytmire
ID: 17882927
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.
0
 
LVL 17

Accepted Solution

by:
Wim ten Brink earned 500 total points
ID: 17887606
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!
0
 
LVL 1

Author Comment

by:rdytmire
ID: 17888225
Thanks,

This was just a test-harness to make sure our theory will work correctly.  I'll clean up stuff in the final code.
0
 
LVL 1

Author Comment

by:rdytmire
ID: 18071017
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.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question