Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.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
C# 加快WebRequest的响应速度?_C#_Web Services_F# - Fatal编程技术网

C# 加快WebRequest的响应速度?

C# 加快WebRequest的响应速度?,c#,web-services,f#,C#,Web Services,F#,我有以下代码: //Send request and get response let req = WebRequest.Create(Uri("https://www.google.com/)) req.Proxy <- null req.Method <- WebRequestMethods.Http.Get use resp = req.GetResponse() //发送请求并获取响应 让req=WebRequest.Create(Uri(“https://www.goog

我有以下代码:

//Send request and get response
let req = WebRequest.Create(Uri("https://www.google.com/))
req.Proxy <- null
req.Method <- WebRequestMethods.Http.Get
use resp = req.GetResponse()
//发送请求并获取响应
让req=WebRequest.Create(Uri(“https://www.google.com/))
req.Proxy您可以通过使用F#异步工作流来实现这一点,并使用
Async.Parallel
来并行化您的请求。您还需要设置允许的并行连接数的.NET限制,以便实际允许更高级别的并行。类似如下:

open System
open System.Net

ServicePointManager.DefaultConnectionLimit <- 20

let checkUrl url = 
  async {
    let req = WebRequest.Create(Uri(url))
    req.Proxy <- null
    req.Method <- WebRequestMethods.Http.Get
    use! resp = req.AsyncGetResponse()
    printfn "Downloaded: %s" url
    return resp.ContentLength }

[ for i in 0 .. 100 -> checkUrl (sprintf "http://www.google.com?%d" i) ]
|> Async.Parallel
|> Async.RunSynchronously
开放系统
开放系统.Net
ServicePointManager.DefaultConnectionLimit Async.RunSynchronously

并行创建WebRequests(到不同端点)……当然,您应该使用
使用!resp=req.AsyncGetResponse()
来减少等待线程的数量。@VasilyKirichenko Oops!不知道我怎么会忽略了这一点。感谢您的纠正!