I have a web API service with the controller as follows.
RoutePrefix("api/Product")]
public class ProductController : ApiController
{
[HttpPost]
[POST("InsertProduct")]
public HttpResponseMessage InsertProduct(ProductDetail product)
{
//logic
}
[HttpGet]
[GET("Item/{itemId}/{itemtypeid}")]
public List<ProductDetail> GetProduct(int itemId, long itemtypeid)
{
//logic
return response;
}
}
Here the GET request is working from both Postman tool(chrome Rest service tester url) and also from the client(refer below). The POST request works fine with the Postman tool. But when I try the same code from the client i am getting the following error "StatusCode: 404, ReasonPhrase: 'Not Found'".
The client code:
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://localhost/ProductService/");
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
string serializedContent = JsonConvert.SerializeObject(new ProductDetail());
StringContent stringContent = new System.Net.Http.StringContent(serializedContent, Encoding.UTF8, "application/json");
HttpResponseMessage response = client.PostAsJsonAsync<ProductDetail>("api/Product/InsertProduct", new ProductDetail()).Result;
How does the same requst works from any external tool but not work from httpclient.
Please help me with this.