sogorman Posted February 20, 2011 Share Posted February 20, 2011 I need to post form data from a page (about 6 fields) to a XML form resource which will responce with a secuss or failure message. After looking around I fount this script that will allow me to post XML data using cURL. my question is can someone point me in the right direction for firing this post off after the user enters data into the fields and hits the submit button. Also what would be the cleanest way to get the form data into the XML section of the below code. What is the best way to handle this? Thanks! <?php $url = "http://www.some_domain.com"; $post_string = '<?xml version="1.0" encoding="UTF-8"?> <rootNode> <innerNode> </innerNode> </rootNode>'; $header = "POST HTTP/1.0 \r\n"; $header .= "Content-type: text/xml \r\n"; $header .= "Content-length: ".strlen($post_string)." \r\n"; $header .= "Content-transfer-encoding: text \r\n"; $header .= "Connection: close \r\n\r\n"; $header .= $post_string; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 4); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header); $data = curl_exec($ch); if(curl_errno($ch)) print curl_error($ch); else curl_close($ch); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.