我正试图通过wp-api发布wordpress但我收到了错误:
An unhandled exception of type 'System.Net.WebException' occurred in System.dll
Additional information: The remote server returned an error: (404) Not Found.
我无法理解,因为当我转到链接时,插件工作正常:http://example.com/wp-json/我正在按预期获取json数据,我没有收到任何错误,告诉我插件工作正常。我的代码是这样的:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace WordpressPost
{
class Program
{
static void Main(string[] args)
{
var uri = "http://www.example.com/wp-json/";
var username = "user";
var password = "password";
var webRequest = WebRequest.Create(uri);
webRequest.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(username + ":" + password));
webRequest.ContentType = "application/json";
webRequest.Method = "POST";
var streamWriter = new StreamWriter(webRequest.GetRequestStream());
string json = "{\"title\":\"Hello World!\",\"content_raw\":\"Content\",\"excerpt_raw\":\"Excerpt\"}";
streamWriter.Write(json);
streamWriter.Close();
var response = (HttpWebResponse)webRequest.GetResponse();
var streamReader = new StreamReader(response.GetResponseStream());
var result = streamReader.ReadToEnd();
Console.WriteLine(result.ToString());
Console.ReadLine();
}
}
}
我已经安装了两个所需的插件JSON基本身份验证,WP REST API,并且还启用了漂亮的永久链接。我做错了什么?
我是c#的新手,这就是我选择基本身份验证登录的原因。