hi I try postdata have been error 415 Unsupported Media Type
- how to solve this case.
- how to add application/json on my typescript as below
import { HttpClient, HttpHeaders } from ‘@angular/common/http’;
import { Injectable } from ‘@angular/core’;
import { environment } from ‘…/…/environments/environment’;
@Injectable({
providedIn: ‘root’
})
export class HttpService {
headers = new HttpHeaders();
// options = { headers: this.headers, withCredintials: false };
options = { headers: this.headers };
constructor(private http: HttpClient) {}
post(serviceName: string, data: any) {
console.log("data asli:", JSON.stringify(data));
const url = environment.apiUrl + serviceName;
return this.http.post(url, JSON.stringify(data), this.options);
}
}
thank you
4 posts - 2 participants