为什么curl 打印XML 响应?
我正在使用curl 来执行post 请求,由于某种原因它会打印xml 响应,这是我不希望发生的事情。我怎样才能摆脱这种行为?
/**
* Send post request
**/
function post_request($sendHttpUrl, $data) {
$ch = curl_init($sendHttpUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
I'm using curl to do post request, for some reason it prints xml response, which is something that I don't want to happend. how can I get rid of this behaviour?
/**
* Send post request
**/
function post_request($sendHttpUrl, $data) {
$ch = curl_init($sendHttpUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在错误的变量上设置了 RETURNTRANSFER 标志。将
$curl
更改为$ch
。You've set the RETURNTRANSFER flag on the wrong variable. Alter
$curl
to$ch
.您的行中有一个拼写错误:“curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);”
应为:
You have a typo in line: "curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); "
It should read: