1
votes

My data is not posting in postman api it gives the error:

dradiobeats.x10host.com/api/areas:1 POST http://dradiobeats.x10host.com/api/areas 401 (Unauthorized) core.js:4002 ERROR HttpErrorResponse {headers: HttpHeaders, status: 401, statusText: "Unauthorized", url: "http://dradiobeats.x10host.com/api/areas", ok: false, …}

My app.component.ts

    import { Component, OnInit } from '@angular/core';
    import { HttpClient } from '@angular/common/http';
    import { map } from 'rxjs/operators';

    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent implements OnInit {
      loadedPosts = [];

      constructor(private http: HttpClient) {}

      ngOnInit() {
        this.fetchPosts();
      }

      onCreatePost(postData: { id: number; content: string }) {
        // Send Http request
        this.http
          .post(
            'http://dradiobeats.x10host.com/api/areas',
            postData
          )
          .subscribe(responseData => {
            console.log(responseData);
          });
      }

How can I resolve this error?

1

1 Answers

-2
votes

The problem do not come from Angular. You are getting the response with the error "Unauthorized" and the HTTP Status code "401".

You are trying to requests the URL "http://dradiobeats.x10host.com/api/areas" and this website tell you that you haven't access to the resource.

Maybe you need to add some credentials like username/password, token or something else to your request.


More information about status codes : https://en.wikipedia.org/wiki/List_of_HTTP_status_codes