我有一个简单的Web服务调用,由.NET(C#)2.0 Windows应用程序通过Visual Studio生成的Web服务代理生成,用于也用C#(2.0)编写的Web服务.这已经工作了几年,并且在它运行的十几个地方继续这样做.
新站点的新安装遇到问题.尝试调用Web服务时,它失败并显示以下消息:
无法为SSL/TLS安全通道建立信任关系
Web服务的URL使用SSL(https://) - 但这已经在很多其他位置工作了很长时间(并且仍在继续).
我在哪里看?这可能是Windows和.NET之间的安全问题吗?如果是这样,我在哪里建立信任关系?我迷路了!
相关:how-do-i-use-webrequest-to-access-an-ssl-encrypted-site-using-https
如何在C#中发送HTTPS GET请求?
我正在寻找一种使用VB .Net验证(或绕过验证)自签名SSL证书的方法.我发现代码在C#中执行此操作并尝试将其转换为VB代码,但我没有运气.
这是C#代码.
这是我尝试过的:
Imports System
Imports System.Net
Imports System.Security.Cryptography.X509Certificates
Public Class clsSSL
Public Function AcceptAllCertifications(ByVal sender As Object, ByVal certification As System.Security.Cryptography.X509Certificates.X509Certificate, ByVal chain As System.Security.Cryptography.X509Certificates.X509Chain, ByVal sslPolicyErrors As System.Net.Security.SslPolicyErrors) As Boolean
Return True
End Function
End Class
Run Code Online (Sandbox Code Playgroud)
然后在Webrequest之前,我有这行代码,这给了我一个错误.
ServicePointManager.ServerCertificateValidationCallback = New System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications)
Run Code Online (Sandbox Code Playgroud)
错误消息是:
Delegate 'System.Net.Security.RemoteCertificateValidationCallback' requires an 'AddressOf' expression or lambda expression as the only argument to its constructor.
Run Code Online (Sandbox Code Playgroud) 我希望用PowerShell向网页发出http请求,这是否可能,如果是这样,我怎么能实现这一点?
我可以向https页面发出请求吗?我能够使用bat文件而不是https来发出http请求,希望我能用PowerShell来https页面请求.
我想在服务器上运行Web抓取脚本.
当前脚本收集指定页面上的html.
$url = "http://websms"
[net.httpWebRequest] $request = [net.webRequest]::create($url)
[net.httpWebResponse] $response = $request.getResponse()
$responseStream = $response.getResponseStream()
$sr = new-object IO.StreamReader($responseStream)
$result = $sr.ReadToEnd()
$result
Run Code Online (Sandbox Code Playgroud)
这在典型的网页上工作正常.但是我想在服务器管理页面上运行它,当然这需要登录.
我想在尝试登录之前我会尝试抓取服务器的登录页面.运行上面的脚本我得到以下结果.
Exception calling "GetResponse" with "0" argument(s): "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."
At C:\temp\web3.ps1:3 char:56
+ [net.httpWebResponse] $response = $request.getResponse <<<< ()
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Run Code Online (Sandbox Code Playgroud)
任何想法如何解决这个问题,或者如果你可以指出我一个不同的方向,所以我可以从服务器的管理html页面刮取元素.
多谢你们!
我正在尝试使用以编程方式发送电子邮件SmtpClient.Send.我正在AuthenticationException尝试发送电子邮件.这是因为证书验证程序失败.
我知道证书是正确的,但我也理解,信任所有证书并不安全,就像这样做的建议:
ServicePointManager.ServerCertificateValidationCallback +=
(sender, certificate, chain, sslPolicyErrors) => { return true; };
Run Code Online (Sandbox Code Playgroud)
所以我想知道测试Thumbprint已知的有效证书指纹是否足够安全,如下所示:
ServicePointManager.ServerCertificateValidationCallback +=
(sender, certificate, chain, sslPolicyErrors) =>
{
if (sslPolicyErrors == SslPolicyErrors.None)
return true;
else if (certificate.GetCertHashString().Equals("B1248012B10248012B"))
return true;
return false;
};
Run Code Online (Sandbox Code Playgroud) 我正在尝试从GDAX获取订单簿(链接到调用的文档)但是当从c#可执行文件执行时我总是得到错误400 - 错误的请求.
在获取实际URL并将其粘贴到我的浏览器中时,它可以正常工作.
String URL = "https://api.gdax.com/products/BTC-USD/book?level=2";
WebRequest request = WebRequest.Create(URL);
WebResponse response = request.GetResponse();
Run Code Online (Sandbox Code Playgroud) 我正在编写一个代码来读取页面并以编程方式下载内容,但它与浏览器的工作方式不同.请注意,我也使用cookie字符串.
我的代码是:
string strUrl = "http:" + "//mgac.webex." + "com";
string cookies_str = "vSeg=post_attendee; s_nr=1321305381566-New; s_lv=1321305381566; s_vnum=1322686800567%26vn%3D1; galaxyb_wl=R2355168776; JSESSIONID=Qlq1TR7Hf09KTsGHr4vv2GnTFF0NGRlLmGyYmMvzY5M29pbZ8yNp!31020270; DetectionBrowserStatus=3|1|32|1|4|2; CK_LanguageID_503319=1; CK_TimeZone_503319=4; CK_RegionID_503319=2; vSeg=post_attendee; s_nr=1321305381566-New; s_lv=1321305381566; s_vnum=1322686800567%26vn%3D1; galaxyb_wl=R2355168776; JSESSIONID=Qlq1TR7Hf09KTsGHr4vv2GnTFF0NGRlLmGyYmMvzY5M29pbZ8yNp!31020270;";
string other_saved_cookies = "screenWidth=1280; CK_CDNHostStatus=akamaicdn.webex.com|1322367753273|1";
string s;
using (WebClient client = new WebClient())
{
client.UseDefaultCredentials = true;
client.Headers.Add(HttpRequestHeader.Cookie, cookies_str);
s = client.DownloadString(strUrl);
}
Run Code Online (Sandbox Code Playgroud)
我得到了这个答案:"无法找到页面......"
当我用Fiddler扫描请求时,我的浏览器收到相同的答案,之后他向同一主机发出了使用SSL的新请求.
如何使用完全相同的请求来接收浏览器等内容
告诉客户的信息在哪里:"需要SSL连接"?
我试图用这个代码从手持设备(Windows CE/Compact框架)调用REST方法:
public static HttpWebRequest SendHTTPRequestNoCredentials(string uri, HttpMethods method, string data, string contentType)
{
ExceptionLoggingService.Instance.WriteLog("Reached
fileXferREST.SendHTTPRequestNoCredentials");
WebRequest request = null;
try
{
request = WebRequest.Create(uri);
request.Method = Enum.ToObject(typeof(HttpMethods), method).ToString();
request.ContentType = contentType;
((HttpWebRequest)request).Accept = contentType;
((HttpWebRequest)request).KeepAlive = false;
((HttpWebRequest)request).ProtocolVersion = HttpVersion.Version10;
if (method != HttpMethods.GET && method != HttpMethods.DELETE)
{
byte[] arrData = Encoding.UTF8.GetBytes(data);
request.ContentLength = arrData.Length;
using (Stream oS = request.GetRequestStream())
{
oS.Write(arrData, 0, arrData.Length);
}
}
else
{
request.ContentLength = 0;
}
}
catch (Exception ex)
{
String …Run Code Online (Sandbox Code Playgroud) ssl compact-framework remote-host socketexception get-request
根据我的要求,我需要从URL获取文件.我试过了,但它总是抛出一个禁止的错误.请尝试解决此问题.请查看我的代码.
var webRequest = WebRequest.Create("https://www.fda.gov/ucm/groups/fdagov-public/@fdagov-drugs-gen/documents/document/ucm509432.pdf");
using (var response = webRequest.GetResponse())
using (var content = response.GetResponseStream())
using (var reader = new StreamReader(content))
{
var strContent = reader.ReadToEnd();
}
Run Code Online (Sandbox Code Playgroud) c# ×6
ssl ×5
.net ×4
powershell ×2
api ×1
asp.net ×1
get-request ×1
html ×1
https ×1
remote-host ×1
trust ×1
vb.net ×1
web-scraping ×1