Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 未找到C wp json api(404)错误_C#_Wordpress_Rest_Wp Api - Fatal编程技术网

C# 未找到C wp json api(404)错误

C# 未找到C wp json api(404)错误,c#,wordpress,rest,wp-api,C#,Wordpress,Rest,Wp Api,我试图通过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. 我无法理解,因为当我转到链接时,插件工作正常:我得到了预期的json数据,没有任何错误告诉我插件工作正常。我的代

我试图通过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.
我无法理解,因为当我转到链接时,插件工作正常:我得到了预期的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,还启用了漂亮的permalinks。我做错了什么


我是c新手,这就是我选择基本身份验证登录的原因。

嘿,你解决了吗?