尽管设置了ServerCertificateValidationCallback,但无法创建SSL / TLS安全通道(Could not create SSL/TLS secure channel, despite setting ServerCertificateValidationCallback)
我正在尝试建立SSL / TLS连接以使用自签名证书测试服务器 。 通过不安全的渠道进行沟通没有问题。
以下是我基于此解决方案编写的示例代码: 使用HttpClient C# 允许不可信的SSL证书 忽略证书错误? .NET客户端连接到ssl Web API
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; var c = new HttpClient(); var r = c.GetAsync("https://10.3.0.1:8443/rest/v1").Result; if (r.IsSuccessStatusCode) { Log.AddMessage(r.Content.Get<string>()); } else { Log.AddMessage(string.Format("{0} ({1})", (int)r.StatusCode, r.ReasonPhrase)); }
也试过这个:
var handler = new WebRequestHandler(); handler.ServerCertificateValidationCallback = delegate { return true; }; var c = new HttpClient(handler); ...
和这个
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
但每次我有一个例外:
InnerException: System.Net.Http.HttpRequestException _HResult=-2146233088 _message=An error occurred while sending the request. HResult=-2146233088 IsTransient=false Message=An error occurred while sending the request. InnerException: System.Net.WebException _HResult=-2146233079 _message=The request was aborted: Could not create SSL/TLS secure channel. HResult=-2146233079 IsTransient=false Message=The request was aborted: Could not create SSL/TLS secure channel. Source=System StackTrace: at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar) InnerException:
我做错了什么? 为什么我无法连接到此服务器(它具有无效的自签名证书)
I'm trying to establish SSL/TLS connection to test server with self-signed certificate. Communication through unsecure channel worked without issues.
Here is my sample code, which I've written based on this solutions: Allowing Untrusted SSL Certificates with HttpClient C# Ignore certificate errors? .NET client connecting to ssl Web API
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; var c = new HttpClient(); var r = c.GetAsync("https://10.3.0.1:8443/rest/v1").Result; if (r.IsSuccessStatusCode) { Log.AddMessage(r.Content.Get<string>()); } else { Log.AddMessage(string.Format("{0} ({1})", (int)r.StatusCode, r.ReasonPhrase)); }
also tried this:
var handler = new WebRequestHandler(); handler.ServerCertificateValidationCallback = delegate { return true; }; var c = new HttpClient(handler); ...
and this
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
but each time I've got an exception:
InnerException: System.Net.Http.HttpRequestException _HResult=-2146233088 _message=An error occurred while sending the request. HResult=-2146233088 IsTransient=false Message=An error occurred while sending the request. InnerException: System.Net.WebException _HResult=-2146233079 _message=The request was aborted: Could not create SSL/TLS secure channel. HResult=-2146233079 IsTransient=false Message=The request was aborted: Could not create SSL/TLS secure channel. Source=System StackTrace: at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar) InnerException:
What do I do wrong? Why I can't connect to this server (which has invalid-self-signed certificate)
原文:https://stackoverflow.com/questions/32994464
最满意答案
只需选择你想回去的哈希,并在你的克隆做:
git reset --hard hash# git push -f origin branch
其中
branch
是您要推送的分支的名称。 瞧。 小心推动力量。 你可能想复制你的工作目录,直到你熟悉它为止。Just pick the hash you want to go back to and in your clone do:
git reset --hard hash# git push -f origin branch
where
branch
is the name of the branch you want to push. Voilà. Be carefully with the force push. You may want to copy your working directory until you are familiar with it.
相关问答
更多-
删除Github提交历史(Delete Github commit history)[2023-12-06]
只需选择你想回去的哈希,并在你的克隆做: git reset --hard hash# git push -f origin branch 其中branch是您要推送的分支的名称。 瞧。 小心推动力量。 你可能想复制你的工作目录,直到你熟悉它为止。 Just pick the hash you want to go back to and in your clone do: git reset --hard hash# git push -f origin branch where branch i ... -
要删除本地最后两个提交,我建议使用: git reset --hard HEAD^^ Rebase是一个完全不同的操作,不会帮助你。 To remove the last two commits locally I'd suggest using: git reset --hard HEAD^^ Rebase is a completely different operation that won't help you here.
-
假设你想要一个看起来像的回购 /rootOfTheRepo .git /walmart /bestbuy 你能做的是: 通过将文件移动到最终仓库中的位置来准备子项目 进入其中一个repo并从另一个获取提交 合并两个master分支 在bash中,它看起来像是从你的本地克隆: cd /path/to/walmartRepo mkdir walmart git mv file1 file2 dir1 dir2 walmart git commit -am "Moved files" cd /pa ...
-
删除.git文件夹可能会导致您的git存储库中的问题。 如果要删除所有的提交历史记录,但是将代码保持在当前状态,那么这样做是非常安全的: 查看 git checkout --orphan latest_branch 添加所有文件 git add -A 提交更改 git commit -am "commit message" 删除分支 git branch -D master 将当前分支重命名为主 git branch -m master 最后,强制更新您的存储库 git push -f origin mas ...
-
我假设您在本地提交了最后两次提交。 然后你想做一个硬重置去2提交回来。 您可以在以后仍然需要的情况下创建两个提交的备份分支: # Make backup branch git branch backup # Do a hard reset of the current branch git reset --hard head~2 Thanks for your answers. I have found the answer in IDE iteslf. Right click the project ...
-
github - 如何去提交历史的开始或滚动更快(github - how to go to beginning of commit history OR scroll faster)[2023-09-20]
我不认为github内置了这个,但有几种方法可以使用URL。 使用page?一些试验和错误page? 让你快速浏览历史的开始: https : //github.com/micropython/micropython/commits/master?page=242 由于您可以输入几乎精确的值,因此您可以输入几乎精确的值:您知道当前最新提交的哈希值和github表示约有8450次提交,因此可以将您带到第一页: https : //github.com/micropython/micropython/犯/主?后 ... -
Github匿名提交历史(Github Anonymous Commit history)[2022-03-13]
我相信Github会根据电子邮件地址计算用户。 因此,如果您将这个wildcats.unh.edu地址添加到Github上的用户帐户,那么这些提交应归于您。 I believe that Github calculates users based on email address. So if you add that wildcats.unh.edu address to your user account on Github, those commits should be attributed to ... -
你应该能够做一个git merge
,因为坏的dev做了一个rebase,会抱怨,但鉴于她只是重新定位到初始提交,听起来解决冲突会相对容易。 如果您的本地存储库不知道提交 - 但是远程存储库知道 - 然后尝试创建远程存储库的新克隆,并查看您正在寻找的提交是否存在。 据我所知,如果提交远程存在,并且克隆存储库,您应该能够访问该提交。 I ended up downloading the zip of the repo from the last good commit on github, the ... -
您可以创建用户页面并粘贴屏幕截图或HTML页面等,但是,否则您需要在那里存储repo。 You could create user pages and paste a screenshot or an HTML page or something like but, but otherwise you need to store the repo there.
-
您描述的步骤似乎是使用BFG工具的正确方法(基于他们的文档)。 请注意,BFG Repo Cleaner仅影响存储库的历史记录,并且不会触及提交历史记录中的最新提交。 换句话说,首先需要清理分支的尖端,然后运行BFG工具。 根据您当前的状态,首先使用或git rm web.config清除当前状态,提交更改,推送所有内容,然后运行BFG清理历史记录。 The steps you described seem like the correct way to use the BFG tool (as based ...