title: POST method calling from service Angular 6 to the REST using web api in asp.net mvc
body: <p>OPTIONS <a href="http://localhost:51156/api/values" rel="nofollow noreferrer">http://localhost:51156/api/values</a> 400 (Bad Request)</p>
  
  <p>Failed to load <a href="http://localhost:51156/api/values" rel="nofollow noreferrer">http://localhost:51156/api/values</a>: Response for preflight has invalid HTTP status code 400.</p>
  
  <p>in service</p>
  
  <pre><code>postTest(student: Student) {
  
      console.log("In service " + student);
      return this._httpService.post('http://localhost:51156/api/students', student);
  
  }
  </code></pre>
  
  <p>in component.ts calling from front end</p>
  
  <pre><code> postTest(){
      console.log("see now ..."+this.student);
      this.uservice.postTest(this.student).subscribe();
    }
  </code></pre>
  
  <p>front end : HTML data</p>
  
  <pre><code> &lt;button type="submit" class="btn btn-primary" (click)="postTest()"&gt;TEST&lt;/button&gt;
  </code></pre>
  
  <p>errors at console debugging:- google chrome</p>
  
  <pre><code>Angular is running in the development mode. Call enableProdMode() to enable 
  the production mode.
  user.component.ts:47 see now ...[object Object]
  user-service.service.ts:100 In service [object Object]
  2zone.js:2969 OPTIONS http://localhost:51156/api/students 400 (Bad Request)
  scheduleTask @ zone.js:2969
  push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ 
  zone.js:407
  </code></pre>
  
  <p>GET works fine for me but
  POST bad request (POST also works well with the POSTMAN tool so no problem in asp.net web api code) searched lots of websites but doesnt rings bells
  With postman i tested json data it works fine with postman
  I making mistake while calling http.post() method forgetting something SYNTAX might wrong in 'angular 6'
  How you people calls post method from angular
  I tested postman works fine
  What syntax in angular 6</p>
  
  <pre><code>OPTIONS http://localhost:51156/api/students 400 (Bad Request)
  Failed to load http://localhost:51156/api/students: Response for preflight 
  has invalid HTTP status code 400.
  Response {_body: ProgressEvent, status: 0, ok: false, statusText: "", 
  headers: Headers, …}
  </code></pre>
  
  <p>Modified to</p>
  
  <pre><code>postTest(){ console.log("see now ..."+this.student); 
  console.log(this.student) this.uservice.postTest(this.student).subscribe( 
  success =&gt; { console.log("success"+success) }, error =&gt; { console.log("errrr 
  "+error) } ); } 
  </code></pre>
  
  <p>and OUTPUT is</p>
  
  <pre><code> errrr Response with status: 0 for URL: null 
  </code></pre>
  
  <p>"Help me to solve quick wasted whole two days in this .........."</p>
  
  <p>Hitting</p>
  
  <pre><code>  http://localhost:51156/api/students from POSTMAN
  </code></pre>
  
  <p>Passing </p>
  
  <p><code>Body{"Sid":1,"fname":"Sss","lname":"XYZ","rollno":666,"address":null,"marks":0," 
      grade":null,"discount":0.0}</code></p>
  
  <p>raw JSON (application/json)</p>
  
  <p>then after send clicked
  status <code>200 OK</code></p>