I have got a Angular Project with a asp.net backend. What I like to do is, to simply post a string to my controller.
I tried the following:
Angular
constructor(private http: HttpClient, @Inject('BASE_URL') private baseUrl: string) { }
httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
};
postString(data:string) {
this.http.post(this.baseUrl + 'api/utility/GetGuid/', "test", this.httpOptions)
.subscribe((guid: string) => {
//do something
});
}
Backend:
[Route("api/[controller]")]
public class UtilityController : Controller
{
[HttpPost]
[Route("GetGuid")]
public JsonResult GetGuid([FromBody]string data)
{
//do something
}
This doesnt seem to work. Dont know how to achieve that I just post the string and get it in the backend.
Hope you can help me.