【问题标题】:ColdFusion CFHTTPPARAM Content-Type?ColdFusion CFHTTPPARAM 内容类型?
【发布时间】:2017-05-22 22:02:52
【问题描述】:

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

错误的 HTTP“Content-Type”标头: “应用程序/八位字节流,多部分/表单数据; 边界=--------------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>

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

【问题讨论】:

  • 使用type="file"时可能会自动添加。尝试将文件二进制文件作为请求正文发送,即&lt;cfhttpparam type="body" value="#FileReadBinary('C:\1_1036.gif')#"&gt;
  • 做到了。谢谢你!
  • 很高兴它成功了。如果该解决方案将来可以帮助其他人,我会写一个答案。

标签: coldfusion upload dropbox-api cfhttp cfhttpparam


【解决方案1】:

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

<cfhttpparam type="body" value="#FileReadBinary('C:\1_1036.gif')#"> 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-15
    • 2013-09-05
    • 2018-07-19
    • 2011-05-05
    • 2011-11-14
    • 2011-04-11
    • 2014-06-01
    相关资源
    最近更新 更多