Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux mono https WebRequest System.Net.WebException(已禁用证书检查)_Linux_F#_Mono - Fatal编程技术网

Linux mono https WebRequest System.Net.WebException(已禁用证书检查)

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

我正在尝试在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 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
  • 德比安·杰西
我尽量小心不要对该url执行太多请求,甚至在
Thread.Sleep
中增加了一些延迟。我仍然能够ping服务器并访问给定的网站,因此我怀疑他们是否阻止了我的IP或类似的内容。异常在第一次尝试时抛出

编辑:

我刚刚用.Net在VisualStudio中测试了代码,在那里,请求似乎永远停止了。所以我进行了调试和调查,最终找到了解决方案

将以下内容添加到我的脚本中:

ServicePointManager.Expect100Continue <- true;
ServicePointManager.SecurityProtocol <- SecurityProtocolType.Tls12

ServicePointManager.Expect100Continue可能是mono如何处理证书的问题,请查看以下内容:。可能是mono如何处理证书的问题,请查看以下内容:。
ServicePointManager.Expect100Continue <- true;
ServicePointManager.SecurityProtocol <- SecurityProtocolType.Tls12