[英]How to get, delete or publish wordpress 4.9 post from powershell using Rest API?
I have found this powershell script on technet. 我在technet上找到了该powershell脚本 。 Description says: Step 1 - install "JSON Basic Authentication" and "WP REST API" by WP REST API Team.
描述说:步骤1-由WP REST API小组安装“ JSON基本身份验证”和“ WP REST API”。 While WP REST API Team says " The REST API is included in WordPress 4.7 " so plugin no longer required.
尽管WP REST API团队说“ REST API包含在WordPress 4.7中 ”,所以不再需要插件。
But now wp-restApi.ps1 script no longer working with WP 4.9. 但是现在wp-restApi.ps1脚本不再可用于WP 4.9。 Returning next error " Invoke-WebRequest : The remote server returned an error: (401) Unauthorized ."
返回下一个错误“ Invoke-WebRequest :远程服务器返回错误: (401)未经授权 。”
How to post to WP 4.7 and newer with powershell Invoke-WebRequest -method post ? 如何使用powershell Invoke-WebRequest -method post发布到WP 4.7及更高版本?
#post title and content
$params = @{
title = "test Rest API post"
content = "test Rest API post content"
status = 'publish'
}
#change username and password before use
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("user:pass@23")))
$header = @{
Authorization=("Basic {0}" -f $base64AuthInfo)
}
$params1=$params|ConvertTo-Json
Invoke-RestMethod -Method post -Uri http://khaoodara.com/wp-json/wp/v2/posts -ContentType "application/json" -Body $params1 -Headers $header -UseBasicParsing
原来,您需要安装WP-API / Basic-Auth Wordpress 插件,并且脚本开始工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.