我正在尝试使用php curl将表单字段和文件发送到Web服务。该表单已经从浏览器传递到代理php客户端Web应用程序,我正在尝试将其转发到Web服务。
当我像这样将数组传递给curl_setopt:
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $this->fields);
我得到一个Array to String通知,虽然它是为了获取一个数组。这是我的数组,传递给构造函数中的$ this->字段。
$fields = array('title'=>$title,
'content'=>$content,
'category'=>$category,
'attachment'=>$_FILES['attachment']);
如果我使用http_build_query
传递字符串,我的网络服务器会抱怨没有多部分/表单数据。
如果我然后使用curl_setopt
强制使用multipart / form enctype,我会收到错误消息,说明没有边界:
org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found
有什么想法吗?
答案 0 :(得分:3)
答案 1 :(得分:0)
试试这个,
$filePath = "abc\\xyz.txt";
$postParams["uploadfile"] = "@" . $filePath;
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, 'https://website_address');
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $postParams);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
if (curl_errno($ch))
{
echo curl_error($ch);
exit();
}
curl_close($ch);