lundi 6 avril 2015

C# wp-json api (404) error not found


Vote count:

0




I'm trying to post on wordpress via wp-api but i'm getting the error:



An unhandled exception of type 'System.Net.WebException' occurred in System.dll

Additional information: The remote server returned an error: (404) Not Found.


I can't understand since the plugin is working fine when I go to the link: http://ift.tt/1NY8cJ4 I'm getting json data as expected, I don't get any error which tells me the plugin is working correctly. My code is like this:



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://ift.tt/1MYCiPL";
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();
}
}
}


I have installed the two needed plugins JSON Basic Authentication, WP REST API and also enabled the pretty permalinks. What am I doing wrong ?


I'm new to c# that's why i chose the basic authentication login.



asked 1 min ago







C# wp-json api (404) error not found

Aucun commentaire:

Enregistrer un commentaire