Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在Chrome Postman WebApi中模拟上载_C#_Asp.net_Asp.net Web Api_Postman - Fatal编程技术网

C# 在Chrome Postman WebApi中模拟上载

C# 在Chrome Postman WebApi中模拟上载,c#,asp.net,asp.net-web-api,postman,C#,Asp.net,Asp.net Web Api,Postman,我试图用Chrome Postman模拟一个文件上传到我的ASP.NET WebApi方法。为此,我在Postman中执行以下步骤 1.打开“邮递员”并从地址栏中选择“邮寄方式”。 2.输入有效的URL。 3.转到地址栏下方的正文部分。 4.从正文部分选择二进制选项。 5.点击“选择文件”按钮选择要上载的文件。 6.选择一个文件 7.确保选择了“Post”选项 8.点击“发送” 然后,我测试MultiPartContent,但是当我逐步执行我的方法时,请求对象似乎没有我需要的信息。下面的异常将被

我试图用Chrome Postman模拟一个文件上传到我的ASP.NET WebApi方法。为此,我在Postman中执行以下步骤

1.打开“邮递员”并从地址栏中选择“邮寄方式”。 2.输入有效的URL。 3.转到地址栏下方的正文部分。 4.从正文部分选择二进制选项。 5.点击“选择文件”按钮选择要上载的文件。 6.选择一个文件 7.确保选择了“Post”选项 8.点击“发送”

然后,我测试MultiPartContent,但是当我逐步执行我的方法时,请求对象似乎没有我需要的信息。下面的异常将被命中

public List<Premium.Model.BureauModUpdate> Post() {
        HttpRequestMessage request = this.Request;
        if (!request.Content.IsMimeMultipartContent()) {
            throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
        }

我还有别的事要做吗?如果有人对此有任何建议或能为我指出正确的方向,我们将不胜感激。

我相信您的内容类型不正确。上传文件时应为
多部分/表单数据

application/x-www-form-urlencoded
仅在发布没有二进制数据的表单时使用

{Method: POST, RequestUri: 'http://localhost/WCAPI/Lookup/BureauModUpdate/CreateNyModUpdates', Version: 1.1, Content: System.Web.Http.WebHost.HttpControllerHandler+LazyStreamContent, Headers:
{
  Cache-Control: no-cache
  Connection: keep-alive
  Accept: */*
  Accept-Encoding: gzip
  Accept-Encoding: deflate
  Accept-Encoding: br
  Accept-Language: en-US
  Accept-Language: en; q=0.8
  Host: localhost
  User-Agent: Mozilla/5.0
  User-Agent: (Windows NT 6.1; WOW64)
  User-Agent: AppleWebKit/537.36
  User-Agent: (KHTML, like Gecko)
  User-Agent: Chrome/55.0.2883.87
  User-Agent: Safari/537.36
  Postman-Token: 23f64855-3b60-3f87-3aa1-ba7d0a841273
  Origin: chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop
  Content-Length: 200284
  Content-Type: application/x-www-form-urlencoded
}}