Whenever I make a http post request, it keeps returning an error message saying "data does not pass correctly". I have tried passing the data through the body and also attempted using json.stringify(). Additionally, I experimented with setting the content type but none of these solutions seemed to work.
const headers = new Headers({ 'Content-Type': 'application/json' });
const options = new RequestOptions({ headers: headers });
this.http_.post('http://localhost:12412/api/employee', remark, options)
.subscribe((data) => {console.log(data)})};
The post call method in the component.ts file is included below:
import { Component, OnInit } from '@angular/core';
import 'rxjs/add/operator/map';
import { Injectable } from '@angular/core';
import { Response, Headers, RequestOptions,Http} from '@angular/http';
import { HttpClient} from '@angular/common/http';
import { Time } from '@angular/common/src/i18n/locale_data_api';
import { NgbDateStruct } from '@ng-bootstrap/ng-bootstrap/datepicker/ngb-date-struct';
import { NgbCalendar } from '@ng-bootstrap/ng-bootstrap/datepicker/ngb-calendar';
import {Ng2OrderModule} from 'ng2-order-pipe';
import {Observable} from "rxjs/Rx";
import { PostChangesService } from './PostChanges.service';
import { Body } from '@angular/http/src/body';
@Component({
selector: 'app-table',
templateUrl: './table.component.html',
styleUrls: ['./table.component.css']
})
export class TableComponent implements OnInit {
constructor(private http: HttpClient, private http_:Http){
}
EditValue(event,remark,log_id) {
console.log(remark+" "+log_id );
const headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
const options = new RequestOptions({ headers: headers });
this.http_.post('http://localhost:12412/api/employee?',remark,options)
.subscribe((data) => {console.log(data)}
)};
}
}
Here is the web api post method that corresponds with the above code:
[HttpPost]
public string Post([FromBody]string remark)
{
if (remark != null)
{
return remark + " _ " ;
}
else
return "data doesn't pass correctly";
}