Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC Web API POST request not working from client application but working from chrome Postman extension
    text
    copied!<p>I have a web API service with the controller as follows.</p> <pre><code>RoutePrefix("api/Product")] public class ProductController : ApiController { [HttpPost] [POST("InsertProduct")] public HttpResponseMessage InsertProduct(ProductDetail product) { //logic } [HttpGet] [GET("Item/{itemId}/{itemtypeid}")] public List&lt;ProductDetail&gt; GetProduct(int itemId, long itemtypeid) { //logic return response; } } </code></pre> <p>Here the <strong>GET</strong> request is working from both <strong>Postman tool</strong>(chrome Rest service tester url) and also from the <strong>client</strong>(refer below). The <strong>POST</strong> request works fine with the Postman tool. But when I try the same code from the client i am getting the following error "<strong>StatusCode: 404, ReasonPhrase: 'Not Found'</strong>".</p> <p>The client code:</p> <pre><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&lt;ProductDetail&gt;("api/Product/InsertProduct", new ProductDetail()).Result; </code></pre> <p>How does the same requst works from any external tool but not work from httpclient.</p> <p>Please help me with this.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload