Issue
I am trying to write simple get request to Jenkins to receive crumb issuer. I need it to run Jenkins job remotely.
Here is my code:
Uri uri = new Uri("http://jenkins/crumbIssuer/api/json");
WebRequest http = HttpWebRequest.Create("http://jenkins/crumbIssuer/api/json");
http.Method = WebRequestMethods.Http.Get;
CredentialCache cc = new CredentialCache();
cc.Add(
new Uri("http://jenkins/crumbIssuer/api/json"),
"NTLM",
new NetworkCredential("user", "pass"));
http.Credentials = cc;
HttpWebResponse response = (HttpWebResponse)http.GetResponse();
Stream stream = response.GetResponseStream();
I received:
System.Net.WebException: 'The remote server returned an error: (403) Forbidden.'
What is my mistake?
Thank you for your time.
Solution
Sorry for that, I have found the solution already.
FYI: http://zetcode.com/csharp/httpclient/.
Check the link and there the chapter: C# HttpClient Basic authentication
Answered By - Vasil
Answer Checked By - Robin (JavaFixing Admin)