如何在JIRA中使用JIRA REST API和HttpWebRequest在C#中进行POST附件?如何使用REST API将附件POST到JIRA?
从documentation under /rest/api/2/issue/{issueIdOrKey}/attachments:
POST
添加一个或多个连接的问题。
此资源需要多部分文章。媒体类型的多部分/表单数据在RFC 1867中定义。大多数客户端库具有可以简化处理多部分帖子的类。例如,在Java中,Apache HTTP Components库提供了一个MultiPartEntity,使得提交多部分POST变得简单。
为了防止XSRF攻击,因为此方法接受多部分/表单数据,所以它具有XSRF保护。这意味着您必须提交X-Atlassian-Token:nocheck的头部,否则将被阻止。
包含附件必须是“文件”
一个简单的例子来上传了一个名为“myfile.txt的”发行REST-123文件中的multipart/form-data的参数的名称:
卷曲-D- -u管理:管理员-X POST -H “X-Atlassian的令牌:NOCHECK” -F “[email protected]” http://myhost.test/rest/api/2/issue/TEST-123/attachments
我
foreach (JIRAAttachments attachm in attachments.attachments)
{
request = HttpWebRequest.Create(
logInformation.GetUri() + "/rest/api/2/issue/" + key + "/attachments"
) as HttpWebRequest;
request.Headers.Add("Authorization: Basic " + logInformation.GetEncodeAuthentication());
request.Method = "POST";
request.ContentType = "multipart/form-data";
request.Headers.Add("X-Atlassian-Token: nocheck [email protected]" + Path.GetFullPath(@"..\Attachments\" + attachm.filename));
request.KeepAlive = true;
request.Proxy = wp;
response = (HttpWebResponse)request.GetResponse();
Stream s = response.GetResponseStream();
FileStream fs = new FileStream(Path.GetFullPath(@"..\Attachments\" + attachm.filename), FileMode.Open);
byte[] write = new byte[256];
int count = fs.Read(write, 0, write.Length);
while (count > 0)
{
s.Write(write, 0, count);
count = fs.Read(write, 0, write.Length);
}
fs.Close();
s.Close();
response.Close();
}
但它返回一个404错误...
什么REST框架? – 2012-08-09 15:03:17
您还可以从文档中提供您的报价链接吗? – 2012-08-09 15:04:26
[JIRA 5.1.2 REST API](http://docs.atlassian.com/jira/REST/latest/) – 2012-08-09 16:15:11