如何将发送文件到API的cURL请求转换为PostMan请求?

时间:2020-02-16 21:57:22

标签: http curl postman

我有以下问题。我可以通过 cURL 执行以下请求:

curl -F file=@"C:\\FE_example.xlsx" http://localhost:8080/api/comp_vibr_and_temp_tab

,效果很好。如您所见,我将文件附加到POST请求(该文件的预期格式为MultiPart)。此API返回的值是JSON。

使用上一个cURL命令可以正常工作,但是尝试通过PostMan执行相同的请求,我得到一个错误。

在PostMan中,我将文件设置为 Body 部分。进入我设置的 Header 部分:

Content-Type: multipart/form-data

尝试执行请求,我得到以下错误消息:

{
    "timestamp": 1581890120091,
    "status": 400,
    "error": "Bad Request",
    "exception": "org.springframework.web.multipart.support.MissingServletRequestPartException",
    "message": "Required request part 'file' is not present",
    "path": "/api/comp_vibr_and_temp_tab"
}

为什么?怎么了?如何将我的 cURL 请求转换为正确的 PostMan 请求?

1 个答案:

答案 0 :(得分:0)

In form-data tab by selecting file option you can browse any file

Content-Type must be multipart/form-data

您可以尝试上述步骤来解决您的问题。