Skip to content

401 (Unauthorized) error when create a post #31

Description

@aymangithub

please.
I have an 401 (Unauthorized) error when I create a post

error: https://localhost/hl-bir/wp-json/wp/v2/posts 401 (Unauthorized)

and this is the function:

createPost(body: any) {
let headers = new Headers();
headers.append('Content-Type', 'application/json;charset=UTF-8');
headers.append('Access-Control-Allow-Origin', '*');
headers.append('Access-Control-Allow-Headers', 'Content-Type, Content-Range, Content-Disposition, Content-Description');
headers.append('Access-Control-Allow-Methods', 'DELETE, HEAD, GET, OPTIONS, POST, PUT');
headers.append('Authorization', 'Basic ' + btoa('username:password'));
headers.append('Cache-Control', 'no-cache');
this.wpApiPosts.create(body, headers)
.toPromise()
.then(response => response.json())
.then(res => {
console.log(res);
})
.catch(err => {
console.log(err);
});
}

this.wpProvider.createPost(
  { titte: 'MyPost3', status: 'publish' }
);

Note that there is no problem in creating a new post from the URL in the chrome browser using the plugin JSON API
https://localhost/hl-bir/api/create_post/?nonce=5bee184120&title=mypost4&status=publish

Thanks in advance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions