我们的内部Redmine服务器只允许我通过HTTPS连接。以下是我尝试通过.NET的HTTPS使用REST API的方法:
"https://redmine.company.com/redmine/"
,将apiKey设置为"ffffffffffffffffffffffffffffffffffffffff"
。使用以下代码从头开始:
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.com
和ffffffffffffffffffffffffffffffffffffffff
只是我真实公司的占位符和我帐户页面上的真实API密钥。在使用WebException超时之前,两次尝试都会挂起一段时间(请参阅尝试2中的挂起注释)。然后我尝试从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的代码(当然还有改编后的网址等)的问题数据。因此,似乎Redmine如何通过HTTPS进行通信可能会有一些特别之处。
如果有人通过HTTPS通过HTTPS成功使用Redmine REST API,我会非常感谢我对我做错的一些指示。
此外,我们将非常感谢有关如何从客户端进行调试的建议。到目前为止,我已经尝试过Fiddler2,但没有成功。只要我启用其“解密HTTPS流量”设置,当我在Internet Explorer中发出请求时,我就不再得到答案。
答案 0 :(得分:1)
我们使用支持HTTP / S连接的redmine-net-api和基于API密钥的身份验证。
RedmineManager rm = new RedmineManager("https://<your-address>", <api-key>, "random-password");
IList<Issue> issues = rm.GetObjectList<Issue>(new NameValueCollection() { { "project_id", <project-id> } });
答案 1 :(得分: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"] = ....
}
答案 2 :(得分:0)
SecurityProtocolType.Tls12
参数的显式传递securityProtocolType
值解决了我的问题:
RedmineManager redmineManager = new RedmineManager(_host, _apiKey,
securityProtocolType: SecurityProtocolType.Tls12);