mathieuturcotte / csharp-oauth-client-library Goto Github PK
View Code? Open in Web Editor NEWC# OAuth Client Library
License: MIT License
C# OAuth Client Library
License: MIT License
I am trying to post JSON to WordPress via the new WP-API, using the WP-API-OAUTH plugin.
Also, I'm using .Net 4.6
I have the access token, consumer key, and associated secrets; and I have used them successfully via Java tools.
However, using this tool in my .Net solution, I get a 401.
I am posting JSON as a raw string converted to Bytes.
My code is below. Any ideas what is wrong?
using OAuth; using OAuth.Base; using OAuth.Authenticator; ... ... ... internal void post(string endpoint, string json) { try { AccessToken accessToken = new AccessToken("AcceSSToKen", "acCEssToKENsecREt"); ClientCredentials credentials = new ClientCredentials("CoNSuMeRKEy", "cONSuMERsECreT"); RequestAuthenticator authenticator = RequestAuthenticatorFactory.GetHmacSha1Authenticator(credentials, accessToken); // Create a request using a URL that can receive a post. WebRequest request = WebRequest.Create(endpoint); authenticator.SignRequest(request); //Set the Method property of the request to POST. request.Method = "POST"; // Create POST data and convert it to a byte array. byte[] byteArray = Encoding.UTF8.GetBytes(json); // Set the ContentType property of the WebRequest. request.ContentType = "application/json"; // Set the ContentLength property of the WebRequest. request.ContentLength = byteArray.Length; // Get the request stream. Stream dataStream = request.GetRequestStream(); // Write the data to the request stream. dataStream.Write(byteArray, 0, byteArray.Length); // Close the Stream object. dataStream.Close(); // Get the response. WebResponse response = request.GetResponse(); // Display the status. Console.WriteLine(((HttpWebResponse)response).StatusDescription); // Get the stream containing content returned by the server. dataStream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(dataStream); // Read the content. string responseFromServer = reader.ReadToEnd(); // Display the content. Console.WriteLine(responseFromServer); // Clean up the streams. reader.Close(); dataStream.Close(); response.Close(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.