I have to create web api in asp.net core console application and want to check api is created?
and want to create token for a web api but unable to create it.
please help me to create token and consume api in console app
-
- string result = string.Empty;
- HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(baseAddress);
- httpWebRequest.ContentType = "application/json; charset=utf-8";
- httpWebRequest.Method = "Get";
- httpWebRequest.Accept = "application/json";
- httpWebRequest.Headers.Add("Authorization", "Bearer " + accessToken);
-
- public string GET(string url)
- {
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
- StreamReader reader;
- try
- {
- WebResponse response = request.GetResponse();
- using (Stream responseStream = response.GetResponseStream())
- {
- reader = new StreamReader(responseStream, System.Text.Encoding.UTF8);
- return reader.ReadToEnd();
- }
- }
- catch (WebException ex)
- {
- WebResponse errorResponse = ex.Response;
- using (Stream responseStream = errorResponse.GetResponseStream())
- {
- reader = new StreamReader(responseStream, System.Text.Encoding.GetEncoding("utf-8"));
- String errorText = reader.ReadToEnd();
- }
- throw;
- }
- }