使用Content-type:application / xml发送POST数据
I want to see XML data that is being POSTed via email.
The process:
1) XML POST is made to a PHP script.
2) The PHP script simply mails me the $_POST data via print_r($_POST, true)
as the message.
I am using PHPMailer and SimpleXML to accomplish this.
Here is my code which POSTs the XML:
$xml = new SimpleXMLElement('<lead/>');
$post_body = array_flip($template['post_body']);
array_walk_recursive($post_body, array($xml, 'addChild'));
$stream_options = array(
'http' => array(
'method' => 'POST',
'header' => "Content-type: application/xml
",
'content' => $xml->asXML(),
),
);
$context = stream_context_create($stream_options);
$response = file_get_contents($template['address'], null, $context);
$post_body
is an array which looks like this:
Array
(
[testbuyer] => buyerName
[tdunn5e@hatena.ne.jp] => testEmail
[Timothy] => leadFirstName
[world] => customTest2
)
Here is my code which sends the email:
try
{
$mailer = new PHPMailer();
$mailer->isSMTP();
$mailer->Host = EMAIL_HOST;
$mailer->Port = EMAIL_PORT;
$mailer->SMTPAuth = true;
$mailer->Username = EMAIL_USERNAME;
$mailer->Password = EMAIL_PASSWORD;
$mailer->setFrom(EMAIL_ADDRESS);
$mailer->addAddress('myemail@gmail.com');
$mailer->Subject = 'Test POST';
$mailer->Body = print_r($_POST, true);
$mailer->send();
$response = 'Mail sent OK';
}
catch (phpmailerException $e)
{
$response = $e->errorMessage();
}
catch (Exception $e)
{
$response = $e->getMessage();
}
I receive the email fine, but the message just shows an empty array. It looks like this:
Array
(
)
Why is this happening? I just want to see the XML in the message so I can verify its all working properly. Any help would be appreciated.
- 点赞
- 写回答
- 关注问题
- 收藏
- 复制链接分享
- 邀请回答
为你推荐
- 还是这个爬虫问题,请指教,可以连上个问答c币一起拿走
- POST请求有效内容的内容类型
- Google App Engine将内容类型更改为text / html,即使将其设置为application / xml
- 2个回答
- 从字符串或字节数组GO创建XML解码器
- xml
- 1个回答
- XML解析返回带换行符的字符串
- xml
- 2个回答
- 使用php curl将XML数据发送到webservice
- 使用http-equiv =“refresh”自动刷新XML RSS文件
- 如何从PHP输出XML字符串
- 验证Curl HTTP Post
- php
- 2个回答
- 通过php://输入原始POST,内容类型为multipart / form-data的表单无法正常工作
- php
- 2个回答
- PHP CURL脚本在第一次请求后获得502/503服务器错误
- php
- 1个回答
- REST(PHP,CURL)PUT / POST XML问题:400错误请求,“无效URL”响应与Walmart OAuth API(邮递员测试)
- 使用错误的文件编码上传CKEditor文件(不是UTF-8)
- php
- 1个回答
- cURL请求:服务器收到POST数据,但返回无效请求
- php
- 1个回答
- 无法从PHP发送content-type:text / xml标头,同时从MYSQL获取数据
- 特定的wordpress localhost /文件夹被重定向到https:// localhost /文件夹,其他文件夹正常工作
- php
- 1个回答
- 如何用PHP解析XML? [重复]
- RESTer发送post请求与表单post请求的区别
- 如何使用跨来源资源共享(CORS)邮递申请
- java-Content-Type=“x-www-form-urlencoded”的参数中文乱码
- java
- 1个回答