如何在OWIN WebAPi C#中获取formData

时间:2019-01-18 09:34:09

标签: c# .net rest owin form-data

我正在从POSTMAN向服务器发送请求:

enter image description here

Content-Type: multipart/form-data

WebApi方法:

using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.Http.Formatting;
using System.Web;
using System.Web.Http;
using System.Web.Http.Cors;

namespace AddMobileAPI.Controllers
{

    [EnableCors(origins: "*", headers: "*", methods: "*")]
    [RoutePrefix("api/alarms")]
    public class AlarmsController : ApiController
    {

        [HttpPost]
        [Route("uploadImage")]
        public IHttpActionResult UploadImageAsync()
        {

            var testValue = HttpContext.Current.Request.Form["test"];


            return Ok("Success !!");
        }
    }
}

此代码在此行给我一个错误

var testValue = HttpContext.Current.Request.Form["test"];

因为当前为空

0 个答案:

没有答案