如何在.NET上通过https使用Redmine REST API?

问题描述 投票:0回答:3

我们的内部Redmine服务器只允许我通过HTTPS连接。以下是我尝试通过.NET的HTTPS使用REST API的方法:

  1. 正如在Using the REST API with .NET中所建议的那样,将主变量设置为"https://redmine.company.com/redmine/",将apiKey设置为"ffffffffffffffffffffffffffffffffffffffff"
  2. 从头开始使用以下代码: using System.IO; using System.Net; class Program { static void Main(string[] args) { ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, error) => true; var request = (HttpWebRequest)WebRequest.Create( "https://redmine.company.com/redmine/issues/149.xml?key=ffffffffffffffffffffffffffffffffffffffff"); request.CookieContainer = new CookieContainer(); request.Method = "GET"; using (var response = request.GetResponse()) // Hangs here using (var responseStream = response.GetResponseStream()) using (var memoryStream = new MemoryStream()) { responseStream.CopyTo(memoryStream); } } }

当然,company.comffffffffffffffffffffffffffffffffffffffff只是我真实公司的占位符和我帐户页面上真正的API密钥。在使用WebException超时之前,两次尝试都会挂起一段时间(请参阅此处的Hangs here comments)。然后我尝试从Redmine服务器下载其他东西(例如time_entries.csv,atom feed等),每次都有完全相同的结果。

到目前为止这么糟糕。但是,如果我将URL https://redmine.company.com/redmine/issues/149.xml?key=ffffffffffffffffffffffffffffffffffffffff复制粘贴到我的浏览器中,我会得到我期望的完全响应。因此,似乎我们的Redmine服务器表现得应该如此,但不知怎的,我无法让它从.NET工作。

我已成功从其他HTTPS站点下载了东西,并设法从http://demo.redmine.org下载了尝试2的代码(当然还有改编的URL等)。因此,似乎Redmine如何通过HTTPS进行通信可能会有一些特别之处。

如果有人通过HTTPS通过HTTPS成功使用Redmine REST API,我会非常感谢有关我做错的一些指示。

此外,非常感谢有关如何从客户端调试此建议的建议。到目前为止,我已经尝试过Fiddler2,但没有成功。一旦我启用其“解密HTTPS流量”设置,当我在Internet Explorer中发出请求时,我就不再得到答案。

c# .net redmine
3个回答
1
投票

我们使用支持HTTP / S连接的redmine-net-api和基于API密钥的身份验证。


        RedmineManager rm = new RedmineManager("https://&ltyour-address&gt", &ltapi-key&gt, "random-password");
        IList&ltIssue&gt issues = rm.GetObjectList&ltIssue&gt(new NameValueCollection() { { "project_id", &ltproject-id&gt } });

0
投票

试试这个,它对我有用:

// Allow every secure connection
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, error) => true;

// Create redmine manager (where URL is "https://10.27.10.10/redmine" for me and redmineKey is my redmine API key
RedmineManager redmineManager = new RedmineManager(redmineURL, redmineKey);

// Create your query parameters
NameValueCollection queryParameters = new NameValueCollection { { "project_id", "4" }, {"tracker_id", "17"}, { "offset", "0" } };

// Perform your query
int issuesFound = 0;
foreach (var issue in redmineManager.GetObjectList<Issue>(queryParameters, out issuesFound))
{
// By default you get the 25 first issues of the project_id and tracker_id specified.
// Play with the offset to get the rest
queryParameters["offset"] = ....
}

0
投票

SecurityProtocolType.Tls12参数的显式传递securityProtocolType值解决了我的问题:

RedmineManager redmineManager = new RedmineManager(_host, _apiKey, 
    securityProtocolType: SecurityProtocolType.Tls12);
© www.soinside.com 2019 - 2024. All rights reserved.