workabyte
workabyte

Reputation: 3755

Does NOT support http GET when sending POST

tried looking around the web a bit and am at a loss. currently setting up a REST api.

locally using postman i send the POST to the end point and all is well. once its pushed to the test server and i run the POST

Status: 405 Method Not Allowed

{
  "message": "The requested resource does not support http method 'GET'."
}

controller looks like and as said, I am able to post locally just not to test server

    [HttpPost, Route("")]
    [ResponseType(typeof(string))]
    public async Task<IHttpActionResult> CreateSomething([FromBody] obj stuff)

c# generated by post man

    var client = new RestClient("http://test-api.someurl.com/makestuff/makethisthing/");
    var request = new RestRequest(Method.POST);
    request.AddHeader("postman-token", "not sure if this is needed but post man put it here");
    request.AddHeader("cache-control", "no-cache");
    request.AddHeader("authorization", "Bearer [A Very long OAuth token]");
    request.AddHeader("content-type", "application/json");
    IRestResponse response = client.Execute(request);

it works fine locally running on local iis (not iis express) on my pc and other dev pc. once put to test server then get that error message. i know i am using post as i am using postman with {{server}} env var and just changing from local to test env so the post itself is not chaining at all

there are currently a handful of other end points in separate web applications that are working fine.

any point in the right direction, thank you

Upvotes: 0

Views: 364

Answers (2)

Chris Pratt
Chris Pratt

Reputation: 239220

Since you're sure you're requesting via POST, but the error unambiguously says you're attempting a GET, the only thing that makes sense is that there's a redirect occurring. A redirect will actually return a 301 or 302 with a Location header. The client then requests that new URL there via GET, even if the original request was a POST. In other words, the flow would be something like: POST -> 302 -> GET -> 405.

Upvotes: 1

Aaron Hudon
Aaron Hudon

Reputation: 5839

Name the action method with a specific route. E.g. /controller/create-something-post/

[HttpPost, Route("create-something-post")]
[ResponseType(typeof(string))]
public async Task<IHttpActionResult> CreateSomething([FromBody] obj stuff)
{
}

Upvotes: 0

Related Questions