Jenkins返回(403)C#

时间:2018-08-02 16:02:22

标签: c# jenkins

我正在尝试使用Jenkins API创建任务。 用户具有权限,但没有办法。 投掷的错误是403。

public void CreateJobWihtXmlTemplateAndRazorRemplaceWhitAutoritazion()
{
    var configData = File.ReadAllText(configCobol);
    byte[] credentialBuffer = new UTF8Encoding().GetBytes("B032560" + ":" +"Agosto20188");
    var webClient = new WebClient();
    webClient.Headers.Add(HttpRequestHeader.Authorization, "Basic " + Convert.ToBase64String(credentialBuffer));
    webClient.UseDefaultCredentials = true;
    webClient.Proxy.Credentials = CredentialCache.DefaultCredentials;

    var jenkinsJobData = FactoryDataProvider.CreateJenkinsJobData();
    var result = Razor.Parse(configData, jenkinsJobData);

    byte[] bytes = System.Text.Encoding.ASCII.GetBytes(result);
    const string FORMAT = "http://{0}:{1}/createItem?name={2}";
    var path =
    string.Format(
    FORMAT,
    "websonardesa03.ar.bsch",
    "8080",
    jenkinsJobData.ProjectName);

    webClient.Headers["content-type"] = " application/xml";
    string response = webClient.UploadString(
    path,
    "POST",
    result
    );
    Assert.AreEqual(HttpStatusCode.OK, HttpStatusCode.OK);
}  

1 个答案:

答案 0 :(得分:0)

This is the FIX

取消选中“防止跨站点请求伪造漏洞利用”