4

I am using RestSharp and doing a POST for the first time I have a number of GET requests that all work fine). The Rest Service is in python but I don't think thats critical to the question. Here is my code:

   var client = new RestClient { BaseUrl = _baseUrl };

  var request = new RestRequest("nameOfPostMethod", Method.POST);
  request.RequestFormat = DataFormat.Json;
  request.AddBody(new { name, description });
  request.AddHeader("accept", "application/json");

  var response = client.Execute(request);

Here is the raw response I get:

    [{"name": "405 - Method Not Allowed", "data": 
    [["Class", "werkzeug.exceptions.MethodNotAllowed"], ["Category", "Client Error"], 
     ["Code", "405"], ["Name", "Method Not Allowed"], ["request.method", "GET"], 
     ["request.url", "http://myUrl/nameOfPostMethod"], ["error.message", "405 Method
    Not Allowed"], ["error.description", null]]}]

the thing that stick out at me are these line where it seems to think I am doing a GET instead of a POST:

 ["request.method", "GET"]

 ["error.message", "405 Method Not Allowed"]

Any suggestion on what I might be doing wrong here?

UPDATE:

I downloaded fiddler and tried to see whats going on and interestingly when i look at the headers, it does show a GET. Here is a screenshot for what I see in fiddler:

enter image description here

I even tried to change:

  client.Execute(request);

to

  client.Post(request);

but it still shows the same thing. Any ideas?

leora
  • 188,729
  • 360
  • 878
  • 1,366

2 Answers2

4

it turns out it was a redirect issue on the webserver side so nothing to do with Rest Sharp

I have requested to delete the question to avoid any confusion.

leora
  • 188,729
  • 360
  • 878
  • 1,366
2

Is this a cross-domain request? If so, then I suspect that RestSharp is making a CORS preflight request before doing the actual HTTP POST. "405 Method Not Allowed" is the proper response to a CORS request if a cross-domain POST is not allowed. I am unsure if that screen shot is showing all the HTTP headers. Does it send the Access-Control-* headers in the GET? That would confirm it.

Moby Disk
  • 3,761
  • 1
  • 19
  • 38