Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

401 (Unauthorized) error when create a post #31

Open
aymangithub opened this issue Jul 26, 2017 · 0 comments
Open

401 (Unauthorized) error when create a post #31

aymangithub opened this issue Jul 26, 2017 · 0 comments

Comments

@aymangithub
Copy link

aymangithub commented Jul 26, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant