将XML发布到API:需要以XML格式将CF7表格发送给API

发布于 2025-01-23 07:52:16 字数 1334 浏览 0 评论 0原文

我想使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文