Solved

Problem with Microsoft.XMLHTTP POST operations

Posted on 2006-11-03
9
681 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

803 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