I am new to coding to REST API and could use some help.
I am trying to get my token in a C# application. I think I am close but I am getting back - Bad request
Here is my code. Any help would be appreciated.
var baseUri = new Uri("https://c2afw1111111111111.caspio.com/");
var encodedConsumerKey = HttpUtility.UrlEncode("111111111111111111111111111");
var encodedConsumerKeySecret = HttpUtility.UrlEncode("111111111111111111111111111");
var encodedPair = Base64Encode(String.Format("{0}:{1}", encodedConsumerKey, encodedConsumerKeySecret));
var requestToken = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri(baseUri, "oauth/token"),
Content = new StringContent("grant_type=client_credentials")
};
You can post now and register later.
If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.
Question
Pingzinggolf
I am new to coding to REST API and could use some help.
I am trying to get my token in a C# application. I think I am close but I am getting back - Bad request
Here is my code. Any help would be appreciated.
var baseUri = new Uri("https://c2afw1111111111111.caspio.com/");
var encodedConsumerKey = HttpUtility.UrlEncode("111111111111111111111111111");
var encodedConsumerKeySecret = HttpUtility.UrlEncode("111111111111111111111111111");
var encodedPair = Base64Encode(String.Format("{0}:{1}", encodedConsumerKey, encodedConsumerKeySecret));
var requestToken = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri(baseUri, "oauth/token"),
Content = new StringContent("grant_type=client_credentials")
};
requestToken.Content.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded") { CharSet = "UTF-8" };
requestToken.Headers.TryAddWithoutValidation("Authorization", String.Format("Basic {0}", encodedPair));
using (HttpClient client = new HttpClient())
{
using (HttpResponseMessage response = client.SendAsync(requestToken).Result)
{
using (HttpContent content = response.Content)
{
var json = content.ReadAsStringAsync().Result;
}
}
}
Link to comment
Share on other sites
2 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.