2

我正在尝试使用 cfhttp 将文件上传到保管箱 api。我从 Dropbox 收到一条错误消息,指出 Content-Type 不正确:

错误的 HTTP“Content-Type”标头:“application/octet-stream,multipart/form-data;boundary=-------------- ---7d0d117230764"。期待“application/octet-stream”、“text/plain; charset=dropbox-cors-hack”之一。

在我看来,ColdFusion 将 multipart.form-data 附加到我在 cfhttpparam 标头中定义的内容类型。我不知道如何防止这种情况。我正在使用下面的代码:

<cfhttp method="post" url="https://content.dropboxapi.com/2/files/upload" result="uploadFile" multipart="no">
    <cfhttpparam type="header" name="Authorization" value="Bearer #DropboxAccessToken#">
    <cfhttpparam type="header" name="Dropbox-API-Arg" value="#serializeJSON(stFields)#">
    <cfhttpparam type="header" name="Dropbox-API-Select-User" value="#DropboxMemberID#">
    <cfhttpparam type="header" name="Content-Type" value="application/octet-stream">
    <cfhttpparam type="file" name="1_1036.gif" file="C:\1_1036.gif">
</cfhttp>

关于可能发生的事情有什么想法吗?

4

1 回答 1

1

由于使用了“multipart/form-data”,因此可能会自动添加type="file"。如果 API 期望内容类型为“application/octet-stream”,则表明它期望文件数据通过 http 请求正文上传,而不是作为命名的“文件”字段。而不是type="file"尝试使用:

<cfhttpparam type="body" value="#FileReadBinary('C:\1_1036.gif')#"> 
于 2017-05-24T14:42:34.510 回答