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

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

问题描述

我正在关注



解决方案

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



设置 Content-Type 转换为 multipart / form-data涉及复杂的概念,即在



如果没有,甚至可能不需要这个 Authorization 标头Web服务器上的任何身份验证。因此,根据您的情况,有效的 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天全站免登陆