TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ritu
1.4k
347
42.9k
how to get tokens
May 18 2021 12:20 PM
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
// code for token
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);
// method for consume api
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
;
}
}
Reply
Answers (
1
)
server.MapPath in c# mvc
How to configure/connect REST API's using C# and Angular?