我试图使用cfhttp将一个文件上传到dropbox。我从Dropbox得到一个错误,说明内容类型是不正确的:
错误的HTTP“内容-类型”标题:“应用程序/八位流、多部分/表单-数据;boundary=-----------------------------7d0d117230764".期待一个“应用程序/八进制流”,“文本/平原;字符集=dropbox 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>对可能发生的事有什么想法吗?
发布于 2017-05-24 14:42:34
由于使用了type="file",可能会自动添加“多部分/表单数据”。如果API期望内容类型为“application/octet”,这意味着它期望文件数据通过http请求体上传,而不是作为一个命名的" file“字段。不要使用type="file",而是尝试使用:
<cfhttpparam type="body" value="#FileReadBinary('C:\1_1036.gif')#"> https://stackoverflow.com/questions/44122798
复制相似问题