本文介绍了使用Curl PHP发送XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前以普通邮寄方式发送表单数据。
我想将其作为XML发送。

I currently send my form data as normal Post.I would like to send it as XML .

当前格式:name = max
我需要的格式:max

Current format : name=maxFormat i need : max

这是我当前的代码:

// This is the data to POST to the form. The KEY of the array is the name of the field. The value is the value posted.
$data_to_post = array();
$data_to_post['title'] = '$title';
$data_to_post['first_name'] = '$first_name';
$data_to_post['surname'] = '$surname';
$data_to_post['email'] = '$email';
$data_to_post['dob'] = '$dob';

// Initialize cURL
$curl = curl_init();

// Set the options
curl_setopt($curl,CURLOPT_URL, $form_url);

// This sets the number of fields to post
curl_setopt($curl,CURLOPT_POST, sizeof($data_to_post));

// This is the fields to post in the form of an array.
curl_setopt($curl,CURLOPT_POSTFIELDS, $data_to_post);

//execute the post
$result = curl_exec($curl);

//close the connection
curl_close($curl);

?>


推荐答案

首先,您必须将数组转换为xml数据。将数组转换为xml的引用链接

First you have to convert your array into xml data. Reffer link for convert array into xml array to xml conversion

现在您必须使用以下代码发送数据

Now you have to send data using following code

$input_xml = ''; //XML Data
$url=''; // URL


    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);

    curl_setopt($ch, CURLOPT_POSTFIELDS,
                "xmlRequest=" . $input_xml);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
    $data = curl_exec($ch);
    curl_close($ch);

这篇关于使用Curl PHP发送XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 20:28