Post jira c# 的附件
Post an attachement to jira c#
我正在尝试 post JIRA 的附件,但出现 404 http 错误。
我之前做了 post 一些评论并且它工作正常。
下面是我的代码
string jsmlogin = "****";
string jsmpass = "****";
string _auth = string.Format("{0}:{1}", jsmlogin, jsmpass);
string _enc = Convert.ToBase64String(Encoding.ASCII.GetBytes(_auth));
string _cred = string.Format("{0} {1}", "Basic", _enc);
string projKey = "DESK-1993";
string postUrl = "https://******/rest/servicedeskapi/request/" + projKey + "/attachments";
string jsmproxy = "http://********";
var clientHandler = new HttpClientHandler();
clientHandler.Proxy = new WebProxy(jsmproxy, true);
HttpClient client = new HttpClient(clientHandler);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _enc);
client.DefaultRequestHeaders.Add("X-Atlassian-Token", "nocheck");
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
MultipartFormDataContent content = new MultipartFormDataContent();
HttpContent fileContent = new ByteArrayContent(File.ReadAllBytes("z.txt.txt"));
content.Add(fileContent, "file","z");
var response = client.PostAsync(postUrl, content).Result;
我认为你得到了一个 404,因为 url 格式不正确...
POST 的 url 应该看起来像
http(s)://{base-url}/rest/api/{apiVersion or latest}/issue/{issue-key}/attachments
对我来说,你的 /request/ 部分看起来很奇怪,应该是 issue
我正在尝试 post JIRA 的附件,但出现 404 http 错误。
我之前做了 post 一些评论并且它工作正常。
下面是我的代码
string jsmlogin = "****";
string jsmpass = "****";
string _auth = string.Format("{0}:{1}", jsmlogin, jsmpass);
string _enc = Convert.ToBase64String(Encoding.ASCII.GetBytes(_auth));
string _cred = string.Format("{0} {1}", "Basic", _enc);
string projKey = "DESK-1993";
string postUrl = "https://******/rest/servicedeskapi/request/" + projKey + "/attachments";
string jsmproxy = "http://********";
var clientHandler = new HttpClientHandler();
clientHandler.Proxy = new WebProxy(jsmproxy, true);
HttpClient client = new HttpClient(clientHandler);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _enc);
client.DefaultRequestHeaders.Add("X-Atlassian-Token", "nocheck");
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
MultipartFormDataContent content = new MultipartFormDataContent();
HttpContent fileContent = new ByteArrayContent(File.ReadAllBytes("z.txt.txt"));
content.Add(fileContent, "file","z");
var response = client.PostAsync(postUrl, content).Result;
我认为你得到了一个 404,因为 url 格式不正确...
POST 的 url 应该看起来像
http(s)://{base-url}/rest/api/{apiVersion or latest}/issue/{issue-key}/attachments
对我来说,你的 /request/ 部分看起来很奇怪,应该是 issue