Last post Mar 05, 2019 05:26 AM by yogyogi
Mar 04, 2019 11:37 AM|samirkarim|LINK
In this example i have 401 not authorized error in GetResponse() method.
The URL has an authentication required popup, and i want to access to the webpage directly.
public ActionResult Contact()
var request = (HttpWebRequest)WebRequest.Create("URL") ;
request.Method = "GET";
var cred = new NetworkCredential("User", "Password","Domain");
var cache = new CredentialCache();
cache.Add(new Uri("URL"), "Basic", cred);
request.Credentials = cache;
var response = (HttpWebResponse)request.GetResponse();
Mar 04, 2019 03:19 PM|bruce (sqlwork.com)|LINK
Mar 05, 2019 05:26 AM|yogyogi|LINK
The API method needs you to provide your Username and Password for accessing it.
You have to find out how to send the credentials to the API i.e. either in through JSON, or through form or through http header.
Once you find out this then you can send the credentials to the API when making the API call.
Consuming ASP.NET Web API is the perfect article which you should reference here.