【发布时间】: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.