Solved

Problem with Microsoft.XMLHTTP POST operations

Posted on 2006-11-03
9
679 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
Comment Utility
0
 
LVL 1

Author Comment

by:rdytmire
Comment Utility
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
Comment Utility
How does your xmlBody looks like?
0
 
LVL 1

Author Comment

by:rdytmire
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 12

Expert Comment

by:Ivanov_G
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

744 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now