403 forbidden, unable to do POST in blog hosted in my server
-
Hi,
To all the good people here, please see if you can help me in this problem of mine. I am using WP-API and oAuth Server plugin to set up a REST connection from a third party C# application. Below is the code.
While it works perfectly on a blog hosted in a free hosting (16mb.com), it chokes when I start using my own server.
During POST it returns a 403 forbidden error. User not allowed to post. I did some changes to htaccess file as read in different blogs, but somehow it dint work. I tried changing wordpress folder permissions and a few tweaks in the code as well.
I think its a server issue, but can anyone help me identify the root cause and any possible workaround.Below is the code I am using:
var request = (HttpWebRequest)WebRequest.Create(“mysite/wp-json/wp/v2/posts”);
request.Headers = new WebHeaderCollection();
request.Headers[“Authorization”] = “Bearer ” + list.Token.getToken;
request.Method = “POST”;string Title = getTitle(file);
string Content = getContent(file);
DateTime datePost = (When.Items[When.SelectedIndex] as ComboBoxItem).Name == “Now” ? DateTime.Now : dt.Value;
var postData = “title=” + Title +
“&content=” + Content +
“&status=publish” +
“&date=” + TimeZone.CurrentTimeZone.ToUniversalTime(datePost).ToString(“yyyy-MM-ddTHH:mm:ss”) +
getSEO(Title,Content);var data = Encoding.ASCII.GetBytes(postData);
request.ContentType = “application/x-www-form-urlencoded”;
request.ContentLength = data.Length;
using (var stream = request.GetRequestStream())
stream.Write(data, 0, data.Length);
var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
var json = JObject.Parse(“{” + JObject.Parse(responseString)[“guid”].First + “}”); // get link of post
MessageBox.Show(“Post posted at “+json[“rendered”].ToString());
- The topic ‘403 forbidden, unable to do POST in blog hosted in my server’ is closed to new replies.