I was granted access to an API. I was told that I must use OAUTH 2.0 to connect to the web API. Here is what I am trying to do.
- I create a WinForms application
- I added a button to the application called btnSend.
- The application has two textboxes on it. (txtToken and txtResults)
- I must connect to the API with https
Lets call the URL for the API "https://localhost/OAUTH"
I have created and deleted about 20 projects so far. This seems to be clear to me when in the context of an aspx page but for some reason I am not translating it correctly to WinForms.
This is what I am trying to use in the context of my send button.
Encoding encoding = new UTF8Encoding();
string postString =
"grant_type=client_credentials&scope=part%20part.rent";
byte[] postData = encoding.GetBytes(postString );
HttpWebRequest request =
(HttpWebRequest)WebRequest.Create("https://localhost/oauth");
string authInfo = txtToken.text; //This is my encoded token.
request.Headers.Add("Authorization", "Basic " + authInfo);
request.Method = "POST";
request.Host = "localhost";
request.ContentType = "application/xwwwformurlencoded";
request.ContentLength = encodedBytes.Length;
Stream newStream = request.GetRequestStream();
newStream.Write(postData , 0, postData .Length);
WebResponse response = request.GetResponse();
txtResults.text = response.ToString();
Aucun commentaire:
Enregistrer un commentaire