【问题标题】:How to get web api request data (Get,Post,Put and Delete) from the raw request itself not receiving it in a method parameters如何从未在方法参数中接收的原始请求本身获取 Web api 请求数据(Get、Post、Put 和 Delete)
【发布时间】:2015-08-06 23:49:16
【问题描述】:

我正在使用WorkContext,其中包含有关当前请求的信息,例如登录用户、当前文化等; 我的问题是我想询问 HttpContext.Current 以从请求中获取数据;(方法主体;我已经知道如何从查询字符串中获取它)我的意思是我想获取 Jason Data 时传递的数据用户在 Get、Post、Put 和 Delete 请求的情况下发出请求;请注意,我想从原始 url HttpContext.Current.Request 获取数据,而不是在方法参数中接收数据,因为我想获取所有方法通用的通用数据

【问题讨论】:

  • 对我的问题有任何帮助

标签: httprequest asp.net-web-api2 asp.net-web-api httpcontext


【解决方案1】:

我认为您想要的属性(假设我理解您的问题)是 HttpContext.Current.Request.RequestType。如果你想要 Json,你可以这样做:

 var rType = new { Method = HttpContext.Current.Request.RequestType };
 var thing = JsonConvert.SerializeObject(rType);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-16
    • 2015-05-17
    • 1970-01-01
    • 2017-03-10
    • 2013-08-03
    • 2013-12-06
    • 2011-04-28
    • 2011-11-03
    相关资源
    最近更新 更多