【问题标题】:PHP: Create XML file and send it with curl?PHP:创建 XML 文件并使用 curl 发送?
【发布时间】:2017-04-02 12:44:01
【问题描述】:

如何使用 PHP 创建 XML 文件,然后使用 curl 发送?

我已经走到这一步了:

<?php 
ob_start();

header("Content-type: text/xml");
header('Content-Disposition: attachment; filename="feed.xml"');
?>

<products>
<?php
foreach ($products as $product)
{
?>
<product></product>
<?php    
}
?>
</products>

<?php
ob_flush();

 $curlOpts = array(
    CURLOPT_URL => 'https://website.com/api/importfile',
    CURLOPT_GET => TRUE,
    CURLOPT_RETURNTRANSFER => TRUE,
    CURLOPT_HTTPHEADER => array('Authorization: api 1234-56789', 'Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'Content-Disposition: form-data; name="feed"; filename="feed.xml"')
);

$ch = curl_init();
curl_setopt_array($ch, $curlOpts);
$response = curl_exec($ch);
curl_close($ch);
?>

但不知道如何继续。如何让它成为“文件”并将其连接到 curl 调用?我必须先将其保存为本地文件吗?还是可以将其保存到 curl 调用中?

【问题讨论】:

  • 你的意思是upload它还是作为post参数发送?
  • API 文档说In order to upload excel or xml file you perform a POST call to the importfile API with the file you wish to import. 然后This request returns an http status code, indicating how the call went, including the ID of the uploaded file. 然后The ImportId is used when calling the PUT importfile API.

标签: php xml curl


【解决方案1】:

看来您只需要使用 curl 发送文件...这可能会有所帮助:

http://code.stephenmorley.org/php/sending-files-using-curl/

【讨论】:

  • 好的,所以我需要先将文件保存到本地?
猜你喜欢
  • 1970-01-01
  • 2013-12-09
  • 2012-08-15
  • 1970-01-01
  • 1970-01-01
  • 2015-04-22
  • 2019-06-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多