0

I don't if it's possible, but I'd like to use RestSharp to post to this method:

    [HttpPost]
    [Authorize]
    public IHttpActionResult AddModel(MyModel model) {
        if (!ModelState.IsValid) {
            return BadRequest();
        }//...

Right now, the method is not being accessed because it's trying to redirect me to the login page, even though I'm logged in when trying to access it.

This is the code that I'm using to access the API:

    [HttpPost]
    public async Task<ActionResult> Add(MyModel m) {
        var client = new RestClient("http://localhost:56571");

        var request = new RestRequest("api/model/addmodel", Method.POST);
        request.RequestFormat = DataFormat.Json;
        request.AddBody(m);

        IRestResponse response = client.Execute(request);
        var content = response.Content;
        Console.WriteLine("DEBUG " + content);

        return View();

    }

Thanks!

Guilherme
  • 1
  • 2

0 Answers0