0

I want to get from Jenkins the last build status via C# code, once I'm triggered a "GET" request it returns me 403 forbidden.

public void GetJsonByGet(string url)
        {
            string json = string.Empty;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("JenkinsEndPoint");
            request.Credentials = new NetworkCredential("User","Password"); //CredentialCache.DefaultCredentials;

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            using (Stream stream = response.GetResponseStream())
            using (StreamReader reader = new StreamReader(stream))
            {
                json = reader.ReadToEnd();
            }
        }  

1 Answers1

0

Check your jenkins has csrf activated or not. if it does you have to implement a call to get the csrf token and use this token for your next requests

fredericrous
  • 2,833
  • 1
  • 25
  • 26