Web API .NET MVC - Http POST - Fiddler 请求发送字符串变量

Web API .NET MVC - Http POST - Fiddler request send string variable

所以我正在做一个 API,我必须将一个巨大的 json 文件和一个变量名称发送到数据库。目前正在使用我的代码发送和读取文件,并且工作正常。

然后我必须发送一个服务名称字符串(可能有“/”字符,这就是为什么我没有把它作为文件名或查询字符串。

我尝试发送此请求 (HTTP POST) :

---------------------------32r23rfewfwfaedef
Content-Disposition: form-data; name="fieldNameHere"; filename="XXXXXX.json"
Content-Type: application/json

{"name":"test"}

<@INCLUDE *C:\....\XXXXXX.json*@>
---------------------------32r23rfewfwfaedef--

问题是我在控制器的任何地方都找不到那个变量...我的代码是这样的:

public HttpResponseMessage Post()
        {
            if (HttpContext.Current.Request.Files.Count != 1)
                throw new HttpResponseException(new HttpResponseMessage()
                {
                    ReasonPhrase = "One file is required, a json in order to create the Swagger.",
                    StatusCode = HttpStatusCode.BadRequest
                });

            SwaggerSaveModel model = new SwaggerSaveModel();

            HttpPostedFile postedFile = HttpContext.Current.Request.Files[0];

            using (System.IO.StreamReader myFile = new System.IO.StreamReader(postedFile.InputStream))
            {
                var XmlObj = new StreamReader(postedFile.InputStream).ReadToEnd();
                model.SwaggerJson = XmlObj.ToString();
            }

            return Request.CreateResponse(HttpStatusCode.Created, "blabla");

        }

文件读取正常,但我找不到 "name" 变量...我也无法更改 json 文件,因为它很招摇,必须完全按照发送的方式使用。

请帮忙..

对于像我这样的未来疑虑,我想出了如何做到这一点。我正在这样发送我的请求:

parameter: FileName

然后像这样访问我的控制器:

HttpContext.Current.Request.Params["HTTP_PARAMETER"]

然后呢returns"FileName"