通过 POSTMAN 发送时 HttpRequest.Files 为空 [英] HttpRequest.Files is empty when sending through POSTMAN

查看:27
本文介绍了通过 POSTMAN 发送时 HttpRequest.Files 为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注这个

解决方案

哼!这非常棘手.除了在工具中明确设置 Content-Type 标头之外,您所做的一切都是正确的.您不得这样做.每当您在工具的 Body 选项卡中附加 form-data 中的文件时,Postman 都会自动检测 Content-Type 并将其发送到您的发帖请求.

Content-Type 设置为multipart/form-data"涉及一个复杂的概念,即设置多个部分的边界,详见

如果您的网络服务器上没有任何身份验证,您甚至可能不需要此 Authorization 标头.因此,在您的情况下,Headers 选项卡实际上应该是空的,即根本没有键值对.

注意:仅供参考,图像文件的正确内容类型是 multipart/form-data,即使您不需要在工具中明确设置它.

I'm following this blog post to upload an image using C# Web API.

The article explains how to do it using ARC and it works fine.

But when I'm trying to do the same using POSTMAN it's failing.

Here is my request snapshot.

解决方案

Humph! This was hell tricky. You are doing everything correct except that you are setting the Content-Type header explicitly in the tool. You must not do that. Whenever you attach the files in form-data in the Body tab in the tool, Postman auto-detects the Content-Type and sends it in your post request.

Setting up Content-Type to "multipart/form-data" involves a complex concept of setting up boundaries of multiple parts as detailed here. So setting up Content-Type header explicitly messes up the request. Heavy lifting of setting up the boundaries is done automatically for you by postman tool which is why it doesn't want you to set the content-type explicitly in this case. Please see how I've set only Authorization header while uploading the image file on my system:

You might not even need this Authorization header if there isn't any authentication on your web server. So effectively Headers tab in your case should simply be empty i.e. no key value pairs at all.

Note: Just for information, the correct content type for image files is multipart/form-data even though you don't need to set it explicitly in the tool.

这篇关于通过 POSTMAN 发送时 HttpRequest.Files 为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆