-1

I have an MVC controller that has a method as follows...

[HttpPost]
[ValidateInput(false)]
public ActionResult TestPost(FormCollection fc) {
  string res = "Form values (" + fc.Count + "):";
  foreach (var key in fc.AllKeys) {
    res += key + "=" + fc[key] + "|";
  }
  return ControllerUtils.XmlView(View("Ok", (object)res));
}

The purpose of this is to test someone else doing an HTTP POST to the controller. The last line just calls a utility method that returns a view containing some XML with the passed string (cast to an object to avoid a compiler error) in one of the tags. The eventual idea is for him to post XML in, which is why I'm returning XML back. I'm sure that bit isn't the issue.

I have someone who is trying to use this from Delphi. For some reason, whenever this method is called, the form collection is empty.

I know this is likely to be a Delphi question, but I wondered if anyone had experienced anything like this. He is using boilerplate code, which shows up as the de-facto method of doing an HTTP POST in hundreds of online articles, blogs and forum posts, so it's hard to say it's wrong, but then the controller code above is so simple that it's hard to see what's wrong here either.

Anyone any ideas why the form collection is always empty? Is there anything I might be doing wrong?

Avrohom Yisroel
  • 8,555
  • 8
  • 50
  • 106
  • how is POST request that is sent to MVC application formulated? You showed action method of a controller, and there is nothing wrong with this code. – Igor Feb 03 '14 at 19:10
  • Igor, please look at the first answer here http://stackoverflow.com/questions/301991/whats-the-simplest-way-to-call-http-post-url-using-delphi as that's basically the same code as you'll find pretty much everywhere. He's using something like that. – Avrohom Yisroel Feb 04 '14 at 14:15
  • Why has this been downvoted? – Avrohom Yisroel Mar 09 '14 at 22:48

2 Answers2

0

I would suggest writing a similar method that outputs res to a string instead of an ActionResult

[HttpPost]
[ValidateInput(false)]
public string TestPost(FormCollection fc) {
  string res = "Form values (" + fc.Count + "):";
  foreach (var key in fc.AllKeys) {
    res += key + "=" + fc[key] + "|";
  }
  return res;
}

Is the form still empty in this case?

roryok
  • 9,325
  • 17
  • 71
  • 138
0

Turned out that the problem was nothing to do with the code itself, but a problem with his code doing a POST to a secure domain. I moved the service to a normal (ie non-SSL) domain, and it worked fine.

So, we have to work out why he can't post to a secure domain, but that's a separate issue from this one.

Thanks to all who replied. Hope this is of some use to someone.

Avrohom Yisroel
  • 8,555
  • 8
  • 50
  • 106