下面的代码在响应内容中给出了相当奇怪的错误ERR: Missing UA30
.我在互联网上任何地方都找不到这个错误.这种情况只发生在某些特定的网站上.
在this repo上同时有另一个版本的代码测试服务器ics
URL.
由于F#和C#共享相同的框架,我怀疑这也会发生在C#上,但我没有测试过它,因为我的C#不是那么流利.
open System.Net.Http
let url = "https://portal.macleans.school.nz/index.php/ics/school.ics"
(* other working urls:
"https://gist.githubusercontent.com/DeMarko/6142417/raw/1cd301a5917141524b712f92c2e955e86a1add19/sample.ics"
"https://www.kayaposoft.com/enrico/ics/v2.0?country=gbr&fromDate=01-01-2023&toDate=31-12-2023®ion=eng"
"https://www.phpclasses.org/browse/download/1/file/63438/name/example.ics"
*)
let getAsync (client: HttpClient) (url: string) =
async {
let! content = client.GetStringAsync url |> Async.AwaitTask
let len = content.Length
printf "%d" len
match len with
| len when len < 50 -> printfn " content: %s" content
| _ -> printfn ""
}
let client = new HttpClient()
getAsync client url
|> Async.RunSynchronously
我try 的所有内容都记录在上面提到的GitHub repo中.
我预计不会出现错误,因为curl
命令能够毫无问题地下载ics
文件-
curl https://portal.macleans.school.nz/index.php/ics/school.ics -o output.ics