Adam
Adam

Reputation: 3013

HTTP post to ASP MVC 3 from a client app

I have an ASP MVC 3 site that allows a user to submit some helpdesk information. I also have a client app (WPF) that users should be able to submit helpdesk information from. I would like to just do a HTTP POST to the same form that the user would use via the web site.

Is this possible? I've tried using RestSharp but I keep getting a 401.2 from my site.

Thoughts?

My MVC controller action is something like:

//
// POST: helpdesk/submit
[HttpPost]
public ActionResult Submit(HelpDeskRequest helpDeskRequest)
{
}

Upvotes: 0

Views: 666

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039060

You could use a WebClient to POST values to your controller action:

using (var client = new WebClient())
{
    var values = new NameValueCollection
    {
        { "Id", "123" },
        { "Name", "abc" },
    };
    var result = client.UploadValues(
        "http://www.domain.com/helpdesk/submit", 
        values
    );
}

and inside the action you will get:

[HttpPost]
public ActionResult Submit(HelpDeskRequest helpDeskRequest)
{
    // helpDeskRequest.Id = 123;
    // helpDeskRequest.Name = "abc";
    ...
}

Upvotes: 1

Related Questions