Jump to content

XML Form Post with Responce from web resource


sogorman

Recommended Posts

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);

?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.