给一个xml格式和一个服务器地址,如何用php写接口
程序员文章站
2022-06-06 19:58:22
...
给一个xml格式和一个服务器地址,怎么用php写接口
我最近正在写,不知道大牛们会怎么写,想学习学习
^…………
------解决方案--------------------
啥接口得给出来吧?
------解决方案--------------------
这是提交数据,调用就简单了,直接fso_get_contents,然后分析xml就行了
$url="https://xxx.com/xml";
$ch = curl_init ($url);
$headers = array(
"POST ".$url." HTTP/1.0",
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Content-length: ".strlen($xmlcontent),
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);
// Apply the XML to our curl call
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlcontent);
$data = curl_exec($ch);
if (curl_errno($ch)) {
die('会议信息出错,有可能会议还未开始!');
exit;
} else {
// Show me the result
//var_dump($data);
curl_close($ch);
}
------解决方案--------------------
我最近正在写,不知道大牛们会怎么写,想学习学习
^…………
------解决方案--------------------
啥接口得给出来吧?
------解决方案--------------------
这是提交数据,调用就简单了,直接fso_get_contents,然后分析xml就行了
$url="https://xxx.com/xml";
$ch = curl_init ($url);
$headers = array(
"POST ".$url." HTTP/1.0",
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Content-length: ".strlen($xmlcontent),
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);
// Apply the XML to our curl call
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlcontent);
$data = curl_exec($ch);
if (curl_errno($ch)) {
die('会议信息出错,有可能会议还未开始!');
exit;
} else {
// Show me the result
//var_dump($data);
curl_close($ch);
}
------解决方案--------------------
相关文章
相关视频
上一篇: 关于php计时器的有关问题