我正在尝试使用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);
}