在C#中使用HttpWebRequest访问Gitlab Api [英] Accessing Gitlab Api with HttpWebRequest in C#

查看:111
本文介绍了在C#中使用HttpWebRequest访问Gitlab Api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试访问我的Gitlab服务器上的API.它可以使用curl,但不能用于我的C#代码.

I am trying to access my the API on my Gitlab server. It works with curl but not from my C# code.

curl --insecure https://gitlab.mycompany.de/dev/TestProjekt/milestones -H "Accept: application/json" -H "Private-Token: my_token"

ServicePointManager.ServerCertificateValidationCallback = (obj, certificate, chain, errors) => (true);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
var req = WebRequest.CreateHttp(new Uri("https://gitlab.mycompany.de/dev/TestProjekt/milestones"));
req.Headers.Add("Private-Token", "my_token");
req.Accept = "application/json";
req.Method = "GET";
var res = req.GetResponse();

我的C#代码导致WebException,消息为底层连接已关闭,发送时发生意外错误"(我收到了德语错误消息,但我确信这是正确的翻译)

My C# code causes an WebException with the message "underlying connection was closed an unexpected error occurred on a send" (i got german error message, but i am convinced that this is the correct translation)

我认为两个请求都应发送相同的数据.我尝试将请求发送到http而不是https,以查看wirehark中的软件包.Curl发送一个附加的标头用户代理",而c#发送连接:保持活动".向C#请求中添加用户代理也无济于事.

In my opinion both requests should send the same data. I tried sending requests to http instead of https to see the packages in wireshark. Curl sends an additional header "user agent" and c# sends "Connection: Keep Alive". Adding a user agent to the C# request won't help either.

有人知道什么可能有所不同吗?

Does anyone have an idea what might be different?

推荐答案

多次清理并重建之后,现在我得到了预期的答案.

After Cleaning and Rebuilding everthing multiple times, I now get the expected answers.

这篇关于在C#中使用HttpWebRequest访问Gitlab Api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆