简体   繁体   English

MVC4-发布字符串始终为null

[英]MVC4 - post string always null

I am using post method (MCV4 - Web API - apicontroller), like this: 我正在使用发布方法(MCV4-Web API-apicontroller),如下所示:

public HttpResponseMessage Post([FromBody]string value)
{
     return Request.CreateResponse(HttpStatusCode.OK, value);
}

I am using google chrome - advanced rest client add-in. 我正在使用谷歌浏览器-高级Rest Client加载项。

  1. For some reason the value is always null (I passed it on raw - payload part of advanced rest client). 由于某种原因,该值始终为null(我在高级rest客户端的raw-有效负载部分传递了该值)。

  2. I need to change always the content type to json/application (manually in google chrome advanced rest client) - Can I force some defaults (on webapiconfig.cs or elsewhere)? 我需要始终将内容类型更改为json / application(通常在google chrome高级rest客户端中)-我可以强制使用一些默认值(在webapiconfig.cs或其他位置)吗?

Thanks :) 谢谢 :)

Hopefully you've already found a solution, but I've been fighting with this the last half hour and came across your question (without a solution), and since I finally got it to work, I figured I'd post my solution: 希望您已经找到了解决方案,但是在过去的半小时中,我一直在与这个问题作斗争,并遇到了您的问题(没有解决方案),并且自从我终于使它起作用以来,我想我会发布我的解决方案:

Leave the Content-Type as: 将Content-Type保留为:

application/x-www-form-urlencoded 应用程序/ x-WWW窗体-urlencoded

In the Raw Payload, enter the string you want to pass in as: 在原始有效负载中,输入要作为以下形式传递的字符串:

=mystring

Note the equal sign before your string with nothing before it. 注意字符串前面的等号,前面没有任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM