简体   繁体   English

如何在ASP.NET MVC 5控制器中的http中返回一个字符串?

[英]How to return a string in http in ASP.NET MVC 5 controller?

I'm refactoring a website using an external service for a form submission, and once they send me the form data, they expect a string of in http response to let them know I've received their POST. 我正在使用外部服务为表单提交重构一个网站,一旦他们向我发送表单数据,他们希望一串http响应让他们知道我收到了他们的POST。

This was what's there previously, when the website was in web forms/aspx. 当网站处于web forms / aspx时,这就是之前的情况。

 Response.ContentType = "text/plain";
 Response.Output.Write("OK");
 Response.Output.Flush();
 Response.Output.Close();

So I tried this first in my controller: 所以我先在我的控制器中尝试了这个:

public ActionResult Index()
{
    //...get the form data...

    return new HttpStatusCodeResult(HttpStatusCode.OK);
}

But this didn't seem to work. 但这似乎不起作用。 Then I tried: 然后我尝试了:

public ActionResult Index()
{
    //...get the form data...

    Response.StatusCode = 200;
    Response.StatusDescription = "OK";

    return new HttpStatusCodeResult(HttpStatusCode.OK, "OK");
}

And it still didn't work. 它仍然无法正常工作。 I don't know if they get the 200 and didn't get the "OK" string? 我不知道他们是否得到200并没有得到“OK”字符串?

EDIT: By didn't work, I meant that the external service didn't receive my string of "OK". 编辑:由于没有工作,我的意思是外部服务没有收到我的“确定”字符串。

简单如下:

return Content("OK", "text/plain");

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

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