5

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.

This was what's there previously, when the website was in 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?

EDIT: By didn't work, I meant that the external service didn't receive my string of "OK".

3
  • If you want to return a string you can do return Content("OK"); Commented Mar 17, 2017 at 14:30
  • What do you mean by "doesn't work"? Commented Mar 17, 2017 at 14:33
  • @BeanFrog My bad, I've edited to add the explanation. Commented Mar 17, 2017 at 15:16

1 Answer 1

9

Simple as:

return Content("OK", "text/plain");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.