Linux mono https WebRequest System.Net.WebException(已禁用证书检查)
我正在尝试在Linux下使用mono和F#对https网页执行一个简单的web请求 昨天,我通过禁用由Linux mono https WebRequest System.Net.WebException(已禁用证书检查),linux,f#,mono,Linux,F#,Mono,我正在尝试在Linux下使用mono和F#对https网页执行一个简单的web请求 昨天,我通过禁用由服务器CertificateValidationCallback完成的证书验证,成功地获得了一个解决方案,但是现在它突然不起作用了 我脚本的相关部分如下所示 #r "../../packages/FSharp.Data/lib/net40/FSharp.Data.dll" #r "System.Xml.Linq.dll" open FSharp.Data open System open Sys
服务器CertificateValidationCallback
完成的证书验证,成功地获得了一个解决方案,但是现在它突然不起作用了
我脚本的相关部分如下所示
#r "../../packages/FSharp.Data/lib/net40/FSharp.Data.dll"
#r "System.Xml.Linq.dll"
open FSharp.Data
open System
open System.IO
open System.Net
open System.Net.Security
open System.Threading
open System.Security.Cryptography.X509Certificates
// disabling certificate validation
ServicePointManager.ServerCertificateValidationCallback <-
new RemoteCertificateValidationCallback(fun _ _ _ _ -> true)
type Either<'a,'b> = Left of 'a
| Right of 'b
let web_reader (url: string) =
try
Thread.Sleep 500
let wr = WebRequest.CreateHttp url
wr.UserAgent <- "test.bot" //I've also tried "safari" without luck
let stream = wr.GetResponse().GetResponseStream()
Right( (new StreamReader(stream)).ReadToEnd() )
with exp -> Left (sprintf "ERROR IN 'web_reader' FOR URL %s\n\n%A" url exp)
web_reader "https://www.jobfinder.dk/"
我真的不明白怎么了。我错过了什么
我正在使用:
- F#4.0
- mono 4.4.1
- 德比安·杰西
Thread.Sleep
中增加了一些延迟。我仍然能够ping服务器并访问给定的网站,因此我怀疑他们是否阻止了我的IP或类似的内容。异常在第一次尝试时抛出
编辑:
我刚刚用.Net在VisualStudio中测试了代码,在那里,请求似乎永远停止了。所以我进行了调试和调查,最终找到了解决方案
将以下内容添加到我的脚本中:
ServicePointManager.Expect100Continue <- true;
ServicePointManager.SecurityProtocol <- SecurityProtocolType.Tls12
ServicePointManager.Expect100Continue可能是mono如何处理证书的问题,请查看以下内容:。可能是mono如何处理证书的问题,请查看以下内容:。
ServicePointManager.Expect100Continue <- true;
ServicePointManager.SecurityProtocol <- SecurityProtocolType.Tls12