Solved

Problem with Microsoft.XMLHTTP POST operations

Posted on 2006-11-03
9
680 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi with SQL Natvie Client 15 86
how to draw animated progressbar in Tvirtualstringtree 5 117
Working this component WebCopy with proxy, help 3 76
CheckListBox usage 3 51
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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

864 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

24 Experts available now in Live!

Get 1:1 Help Now