rdytmire
asked on
Problem with Microsoft.XMLHTTP POST operations
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;
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
vHttp.open(operation, url, false, EmptyParam,EmptyParam);
vHttp.send(xmlBody);
result := vHttp.responseText;
end;
http://www.perfectxml.com/msxmlAnswers.asp?Row_ID=37
ASKER
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.
How does your xmlBody looks like?
ASKER
I found the problem. The declaration of xmlBody: string; was the issue. the following line of code fixed the issue.
vHttp.send(WideString(xmlB ody));
It seems I needed to convert the type of string before making the oleCall.
vHttp.send(WideString(xmlB
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.
'<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.
ASKER
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks,
This was just a test-harness to make sure our theory will work correctly. I'll clean up stuff in the final code.
This was just a test-harness to make sure our theory will work correctly. I'll clean up stuff in the final code.
ASKER
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.