gpt4 book ai didi

c# - 如何使用C#下载jira中的附件

转载 作者:行者123 更新时间:2023-12-02 13:56:44 29 4
gpt4 key购买 nike

我正在尝试使用 jira techtalk 从 jira 下载附件,以获取问题和附件。

foreach (var img in issue.fields.attachment)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
dynamic item = serializer.Deserialize<object>(img.ToString());

System.Drawing.Image attachImg = Utilities.DownloadImageFromUrl(item["content"].ToString());
if (attachImg != null) {
var sPath = Path.Combine(Server.MapPath("~/Content/Uploads/"), item["filename"].ToString());
attachImg.Save(sPath);
}

}

在utilities.downloadimagefromurl中,这是完整的代码:

public static System.Drawing.Image DownloadImageFromUrl(string imageUrl)
{
System.Drawing.Image image = null;

try
{
System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(imageUrl);
webRequest.AllowWriteStreamBuffering = true;
webRequest.Timeout = 30000;

System.Net.WebResponse webResponse = webRequest.GetResponse();

System.IO.Stream stream = webResponse.GetResponseStream();

image = System.Drawing.Image.FromStream(stream);

webResponse.Close();
}
catch (Exception ex)
{
return null;
}

return image;
}

但返回 null。

有人知道怎么做吗?

谢谢

最佳答案

我在jira API中找到了下载附件的解决方案:我正在使用tecktalk Jira Rest Client https://github.com/techtalk/JiraRestClient

代码如下:

using (WebClient webClient = new WebClient())
{

webClient.DownloadFile(new Uri(remoteUri + "?&os_username=usernamehere&os_password=passwordhere"), dPath);

}

使用您的 jira 登录用户名和密码。

关于c# - 如何使用C#下载jira中的附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24821484/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com