Ionic 2 WP-REST API post 请求 401 错误,headers 设置为基本身份验证

Ionic 2 WP-REST API post request 401 error with headers set for basic authentication

我正在开发一个简单的应用程序,通过 wp-rest api 在 Wordpress 中创建 post。一切(创建、更新、删除 posts)在 postman 上工作正常。我什至可以在我的应用程序中使用相同的 api 获取 posts。但是当我尝试创建 posts 时,它在控制台中显示 401 Unauthorized 错误。 这是我的请求代码。

//create post by api
createPost(title,content){
    var headers = new Headers();
    headers.append('Authorization', 'Basic '+btoa('tarun:iamtarun'));
    headers.append("Content-Type", "application/json");
    return this.http.post(this.postUrl+'?title='+title+'&content='+content , {
        headers:headers 
    })
    .map(res => res.json());
}

请帮忙。

httppost请求的结构是

post(url: string, body: any, options?: RequestOptionsArgs): Observable<Response>;

所以请求应该是,

return this.http.post(this.postUrl+'?title='+title+'&content='+content ,{}, { headers:headers })

body 是一个空对象。