将XML发布到API:需要以XML格式将CF7表格发送给API
我想使用Post方法将联系表格7字段填充数据发送到API。有人可以帮我完成这项任务吗?
我将以下代码放在自定义页面模板中,它正在生成正确的响应代码,但在API上未收到数据。
//show contact form 7
echo do_shortcode( '[contact-form-7 id=""]' );
//collect fields value
$FirstName = $_POST['FirstName'];
$LastName = $_POST['LastName'];
$Email = $_POST['Email'];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://post.example.com/LPost',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'<ldlead>
<FirstName>'.$FirstName.'</FirstName>
<LastName>'.$LastName.'</LastName>
<Email>'.$Email.'</Email>
</ldlead> ',
CURLOPT_HTTPHEADER => array(
'accept: application/json',
'accept-encoding: gzip, deflate',
'accept-language: en-US,en;q=0.8',
'content-type: application/xml',
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
接收数据样本:应以这种格式收到数据
<ldlead>
<FirstName>First Name</FirstName>
<LastName>LastName</LastName>
<Email>Email id</Email>
</ldlead>
I want to send contact form 7 field filled data to an api using post method. Can anyone please help me complete this task?
I have put below code in custom page template and it is generating correct response code but data is not getting received on API.
//show contact form 7
echo do_shortcode( '[contact-form-7 id=""]' );
//collect fields value
$FirstName = $_POST['FirstName'];
$LastName = $_POST['LastName'];
$Email = $_POST['Email'];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://post.example.com/LPost',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'<ldlead>
<FirstName>'.$FirstName.'</FirstName>
<LastName>'.$LastName.'</LastName>
<Email>'.$Email.'</Email>
</ldlead> ',
CURLOPT_HTTPHEADER => array(
'accept: application/json',
'accept-encoding: gzip, deflate',
'accept-language: en-US,en;q=0.8',
'content-type: application/xml',
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Recevived data sample: Data should be received in this format
<ldlead>
<FirstName>First Name</FirstName>
<LastName>LastName</LastName>
<Email>Email id</Email>
</ldlead>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论