Forum Moderators: coopster
For example, a lead form is complete with Name, Address, Phone, and so on. I capture the form data and submit as an XML document. This particular advertiser will only accept data as an "External XML Post." I tried using Javascript and PHP with cURL, but I'm going in circles trying snippets of other people's code -- it's been a week. At this point all I want to do is assume IE7 (nothing else!) and no data checks, just "here's the XML, here's the external URL" and show me that HTTP POST actually works. Right now I'm thinking it's a bunch of junk :-) Someone please help.
Here's my server info:
PHP Verion 4.4.4
Apache/2.0.46 (Red Hat)
CURL support enabled
CURL Information libcurl/7.15.4
DOM/XML enabled
DOM/XML API Version 20020815
libxml Version 20510
HTML Support enabled
XPath Support enabled
XPointer Support enabled
XML Support active
XML Namespace Support active
Here's a sample of XML, let's call it "data.xml"
<?xml version="1.0" encoding="UTF-8"?>
<DataFormSubmit>
<individual id="12345">
<FirstName></FirstName>
<LastName></LastName>
<Address></Address>
<Phone></Phone>
</individual>
</DataFormSubmit>
POST XML document to URL on an external website for example:
http://www.example.com/othersite/xml.aspx
Response XML is equally simple. There is no mention of MethodCall, MethodResponse and Params like the books say, so please don't use those elements in your reply to me. There is mention of field requirements like "Text field" "255 character max" "Numeric" but I think this can be handled by the input validation scripts. I'm just trying to POST and get a response.
I've received errors refering to "permission denied" "access denied" "object expected" but at this point I've edited my code so many times I don't know what's right or wrong any more. Here's one of my failed cURL examples:
<?php
// XML data as string
$request = '<?xml version="1.0" encoding="UTF-8"?>';
$request .= '<DataFormSubmit>';
$request .= '<individual id="12345">';
$request .= '<FirstName></FirstName>';
$request .= '<LastName></LastName>';
$request .= '<Address></Address>';
$request .= '<Phone></Phone>';
$request .= '</individual>';
$request .= '</DataFormSubmit>';
// Create Headers
$header[] = "Host: www.example.com";
$header[] = "Content-type: text/xml";
$header[] = "Content-length: ".strlen($request) . "\r\n";
$header[] = $request;
// Send using CURL
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, "http://www.example.com/othersite/xml.aspx"); // URL to post
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); // return into a variable
curl_setopt( $ch, CURLOPT_HTTPHEADER, $header ); // headers from above
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'POST' ); // special POST with specified Content-type
$result = curl_exec( $ch ); // runs the post
curl_close($ch);
echo $result; // echo reply response
?>
And I tried a Javascript variations using code like
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP") but I'll save that for a followup post since this is getting long.
Anyone out there doing external XML form post?
[edited by: dreamcatcher at 3:10 pm (utc) on Mar. 18, 2007]
[edit reason] Use example.com, thanks. [/edit]
I think you're saying post the form data variables to a script on another internal web page, then "HTTP Post" the XML to the external destination?
I've tried something similar and I'm all for that. At this time I'm just not sure what the "HTTP Post" script should look like: cURL, Ajax, does anyone have a script that works on hand?
I don't know if IE7 is blocking my HTTP Post or if its my bad code, or if it's my server set up. I'm looking for a simple script that either HTTP Posts or Posts any way to the live destination. No data checks (I'll deal with that later), just the header elements and "POST" function in a working script.
Assume the XML data is ready on it's own page, data.xml for example, how do I send it to the destination without running into security blocks in IE7 and my server?
If it's not a simple answer and someone knows someone who can work with me fee based let me know. I can't imagine it's a difficult thing, just need to find someone who does this sort of thing regularly.
Thanks.
I think you're saying post the form data variables to a script on another internal web page
Yes.
, then "HTTP Post" the XML to the external destination?
No. ;)
I mean, simply change this line to a faked up page on your own server, like this:
Old line:
//curl_setopt( $ch, CURLOPT_URL, "http://www.example.com/othersite/xml.aspx"); // URL to post
curl_setopt( $ch, CURLOPT_URL, "http://www.example.com/path/on/my/site/test.php"); // URL to post
Then in test.php you could simple spit out the POST data, which your curl process will read and return to you in the originating script:
test.php
<pre>
<?php print_r($_POST);?>
</pre>
You can then tweak your curl code until you have it where you need it.
Posting the data on an internal web page first will allow you to make sure you have all your headers and body data correct before you even think of sending it off over the pipe to the receiver. Once you have everything nailed down, you can change the url to the receiver as opposed to you internal site.
I noticed that I mentioned to change the curl_setopt parameter to reflect that change but forgot to let you know you need to change your header "Host" as well. Don't forget to change this line to your internal server too during testing!
// Create Headers
$header[] = "Host: www.example.com";