I'm trying top send a post request on angular and im pretty sure that the problem is not in the backend side since i used postman and it worked on postman.
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
@Injectable()
export class ConHttpService {
private headers: HttpHeaders;
private accessPointUrl: string = 'https://localhost:44340/api/contact';
constructor(private http: HttpClient) {
this.headers = new HttpHeaders({'Content-Type': 'application/json; charset=utf-8'});
}
public addcon(payload) {
console.log("hi") //prints hi
console.log(this.accessPointUrl, payload, {headers: this.headers}) //gives a link that take me to a url full of json of targeted database but without my added object
return this.http.post(this.accessPointUrl, payload, {headers: this.headers});
}
}
in the sending component:
onSubmit(){
console.log(this.contactForm.value)
this.conhttp.addcon(this.contactForm.value)
}