将cURL转换为coldfusion

将cURL转换为coldfusion,coldfusion,unirest,Coldfusion,Unirest,我正在从事一个涉及RESTful Api的项目,我需要将附件上载到另一台服务器,如果上载成功与否,该服务器将给我响应。PS:他们要求我们使用PUT上传附件 我可以使用cURL来完成此过程: curl -s -u "username:password" -H "accept: application/json" -F "attachment=@file_path" -X PUT https://example.com/MailManagement/ws/v3/send/message/attach

我正在从事一个涉及RESTful Api的项目,我需要将附件上载到另一台服务器,如果上载成功与否,该服务器将给我响应。PS:他们要求我们使用
PUT
上传附件

我可以使用
cURL
来完成此过程:

curl -s -u "username:password" -H "accept: application/json" -F "attachment=@file_path" -X PUT https://example.com/MailManagement/ws/v3/send/message/attachment
但是当我通过
cfhttp
编写它时,响应是
200ok
,但是他们的服务器会告诉我

“分析请求时出现问题”

我使用了
cfhttpparam type=“file”
,如下所示,解析请求时它会说
有问题

<cffunction name="uploadAttachment" access="remote" description="Upload An Attachment">
    <cfhttp url = "https://example.com/MailManagement/ws/v3/send/message/attachment" method="put" result="httpResp" username="username" password="password">
        <cfhttpparam type="header" name="Content-Type" value="multipart/form-data">
        <cfhttpparam type="file" file="C:\temp\1.txt" name="1.txt">
    </cfhttp>
    <cfset response_message = "#httpResp.tostring()#">
    <cfreturn response_message>
</cffunction>

尝试设置
而不是
“multipart/form data”
@Miguel-F我尝试了这个,它告诉我
需要上传多部分文件
,所以我想我必须使用
多部分/表单数据
,然后保留多部分标题并尝试添加这个
。您的其他两个示例中似乎都存在这种情况。请尝试设置
而不是
“多部分/表单数据”
@Miguel-F我尝试过这个,它告诉我需要
多部分文件上载
,因此我想我必须使用
多部分/表单数据
,然后保留多部分标题并尝试添加此
。你的其他两个例子似乎都是这样。
HttpResponse<JsonNode> response = Unirest.put("https://example.com/MailManagement/ws/v3/send/message/attachment")
              .header("accept", "application/json")
              .basicAuth("username", "password") // provide Direct address and password
              .field("attachment", new File("")) // provide file to upload
              .asJson();
JsonNode json = response.getBody(); // json response