【发布时间】:2010-04-15 10:57:44
【问题描述】:
我正在尝试使用 php curl 将表单字段和文件发送到 Web 服务。该表单已从浏览器传递到代理 php 客户端 Web 应用程序,我正在尝试将其转发到 Web 服务。
当我像这样将数组传递给 curl_setopt 时:
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $this->fields);
我收到了一个 Array to String 的通知,尽管它是用来接收一个数组的。这是我在构造函数中传递给 $this->fields 的数组。
$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
有什么想法吗?
【问题讨论】: