getting 201 status code instead of 200 when i hit an api url in my controller

Muhammad Kaleem asked on April 14, 2019 06:58

    i'm using asp.net mvc, in controller i have create a method by which i want to get token by api, first i was trying with different code that was give exception of status code 415, unsupported media type, now i have modify my code and now its gives 201 instead of 200 in "response" variable but i want to get token in response, in case of 201 server only send the reference of data not original data, please anyone can suggest me, any help will be highly appreciated
    thanks
using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("abc.com/");
                var response = client.PostAsJsonAsync("api/token","{}").Result;

                if (response.IsSuccessStatusCode)
                {
                    Console.Write("Success");
                }
                else
                    Console.Write("Error");
            }



    i want to get token by 200 status code

Recent Answers


Roman Hutnyk answered on April 15, 2019 07:28

201 status is correct one for the operation you perform: You're sending POST request. The intention of POST request is to create new data record and 201 status means created. See docs.

As long as you control the code you're in charge what's being returned in the response.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.