To properly utilize the @angular/common/http
module, make sure to import it in your Angular application like this:
import { HttpClient, HttpHeaders } from '@angular/common/http';
In this context, HTTP
corresponds to HttpClient
, and Headers
corresponds to HttpHeaders
.
Avoid using RequestOptions; instead, structure your requests as demonstrated below:
Example:
let headers = new HttpHeaders({
'Content-Type': 'application/json'
});
let options = {
headers: headers
}
this.http.post(URL, param, options)....
For further guidance, consult the official documentation at https://angular.io/guide/http#adding-headers
Remember to include HttpClientModule in your main module setup [https://angular.io/guide/http#setup]
Example:
@NgModule({
imports: [
BrowserModule,
// Import HttpClientModule after BrowserModule.
HttpClientModule,
],
declarations: [
AppComponent,
],
bootstrap: [ AppComponent ]
})
export class AppModule {}