FsHttp
FsHttp copied to clipboard
System.FormatException: The format of value '' is invalid.
Hello there!
I'm trying to make a request like this
#r "nuget: FsHttp"
open FsHttp
http {
POST "https://api.jspm.io/generate"
body
json ("""{
"install": [ "lodash" ],
"env": [ "browser", "module" ],
"graph":true,
"provider": "jspm"}""")
}
|> Request.send
|> Response.toText
|> printfn "%s"
the expected JSON content is the following
{
"staticDeps": [
"https://ga.jspm.io/npm:[email protected]/lodash.js"
],
"dynamicDeps": [],
"map": {
"imports": {
"lodash": "https://ga.jspm.io/npm:[email protected]/lodash.js"
}
},
"graph": {
"https://ga.jspm.io/npm:[email protected]/": {
"lodash.js": {}
}
}
}
but I get the following instead
PS C:\Users\scyth\repos\scripts> dotnet fsi script2.fsx
System.FormatException: The format of value '' is invalid.
at System.Net.Http.Headers.HttpHeaderParser.ParseValue(String value, Object storeValue, Int32& index)
at System.Net.Http.Headers.HttpHeaders.ParseAndAddValue(HeaderDescriptor descriptor, HeaderStoreItemInfo info, String value)
at System.Net.Http.Headers.HttpHeaders.Add(HeaderDescriptor descriptor, String value)
at [email protected](CancellationToken ctok)
at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, b result1, FSharpFunc`2 userCode) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 528
at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 112
--- End of stack trace from previous location ---
at Microsoft.FSharp.Control.AsyncResult`1.Commit() in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 454
at Microsoft.FSharp.Control.AsyncPrimitives.QueueAsyncAndWaitForResultSynchronously[a](CancellationToken token, FSharpAsync`1 computation, FSharpOption`1 timeout) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 1140
at Microsoft.FSharp.Control.FSharpAsync.RunSynchronously[T](FSharpAsync`1 computation, FSharpOption`1 timeout, FSharpOption`1 cancellationToken) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 1511
at <StartupCode$FSI_0002>.$FSI_0002.main@() in C:\Users\scyth\repos\scripts\script2.fsx:line 6
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
Stopped due to error
When I use nightingale I get this log, not sure if it helps at all
Method: POST, RequestUri: 'https://api.jspm.io/generate', Version: 2.0, Content: System.Net.Http.StringContent, Headers:
{
Content-Type: application/json; charset=utf-8
}
StatusCode: 200, ReasonPhrase: '', Version: 2.0, Content: System.Net.Http.StreamContent, Headers:
{
Server: Google
Server: Frontend
Date: Fri, 30 Sep 2022 00:16:50 GMT
Access-Control-Allow-Origin: *
Content-Type: application/json
}
Let me know if you need further information
Thank you for the issue report. Unfortunately, I cannot reproduce it. If you have further info, please share them. In my test, I use VS2022, .Net SDK 6.0.304 and a plain .fsx file with the content copied from above.
Could you omit the |> Response.toText |> printfn "%s"
and just run this in FSI:
#r "nuget: FsHttp"
open FsHttp
http {
POST "https://api.jspm.io/generate"
body
json """
{
"install": [ "lodash" ],
"env": [ "browser", "module" ],
"graph":true,
"provider": "jspm"
}
"""
}
|> Request.send
This will print the request, and response + content in the FSI output - like this:
REQUEST
--------
POST https://api.jspm.io:443/generate HTTP/1.1
Cookie :
Content-Type : application/json
Content-Length : 108
===content===
{
"install": [ "lodash" ],
"env": [ "browser", "module" ],
"graph":true,
"provider": "jspm"}
RESPONSE
---------
HTTP/1.1 200 OK
Access-Control-Allow-Origin : *
Transfer-Encoding : chunked
Date : Mon, 03 Oct 2022 09:04:37 GMT
Server : Google, Frontend
Content-Type : application/json
===content===
{
"staticDeps": [
"https://ga.jspm.io/npm:[email protected]/lodash.js"
],
"dynamicDeps": [],
"map": {
"imports": {
"lodash": "https://ga.jspm.io/npm:[email protected]/lodash.js"
}
},
"graph": {
"https://ga.jspm.io/npm:[email protected]/": {
"lodash.js": {}
}
}
}
Ah yes, I forgot to include that I'm on .NET7 previews
here's the dotnet --info
output
.NET SDK:
Version: 7.0.100-rc.1.22431.12
Commit: f1cf61e1c0
Runtime Environment:
OS Name: Windows
OS Version: 10.0.22000
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\7.0.100-rc.1.22431.12\
Host:
Version: 7.0.0-rc.1.22426.10
Architecture: x64
Commit: 06aceb7015
.NET SDKs installed:
5.0.408 [C:\Program Files\dotnet\sdk]
6.0.201 [C:\Program Files\dotnet\sdk]
6.0.202 [C:\Program Files\dotnet\sdk]
6.0.203 [C:\Program Files\dotnet\sdk]
6.0.304 [C:\Program Files\dotnet\sdk]
6.0.401 [C:\Program Files\dotnet\sdk]
7.0.100-rc.1.22431.12 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.0-rc.1.22427.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.29 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.0-rc.1.22426.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.0-rc.1.22427.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables:
Not set
global.json file:
Not found
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download
I tried removing the other pipes as you suggested
PS C:\Users\scyth> dotnet fsi
Microsoft (R) F# Interactive version 12.0.5.0 for F# 7.0
Copyright (c) Microsoft Corporation. All Rights Reserved.
For help type #help;;
> #r "nuget: FsHttp"
open FsHttp
http {
POST "https://api.jspm.io/generate"
body
json """
{
"install": [ "lodash" ],
"env": [ "browser", "module" ],
"graph":true,
"provider": "jspm"
}
"""
}
|> Request.send;;
[Loading C:\Users\scyth\.packagemanagement\nuget\Projects\21160--a3433b23-913b-47d0-b283-151d8b574fa8\Project.fsproj.fsx]
module FSI_0002.Project.fsproj
Binding session to 'C:/Users/scyth/.nuget/packages/fshttp/9.1.2/lib/net6.0/FsHttp.dll'...
System.FormatException: The format of value '' is invalid.
at System.Net.Http.Headers.HttpHeaderParser.ParseValue(String value, Object storeValue, Int32& index)
at System.Net.Http.Headers.HttpHeaders.ParseAndAddValue(HeaderDescriptor descriptor, HeaderStoreItemInfo info, String value)
at System.Net.Http.Headers.HttpHeaders.Add(HeaderDescriptor descriptor, String value)
at System.Net.Http.Headers.HttpHeaders.Add(String name, String value)
at [email protected](CancellationToken ctok)
at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, b result1, FSharpFunc`2 userCode) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 528
at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 112
--- End of stack trace from previous location ---
at Microsoft.FSharp.Control.AsyncResult`1.Commit() in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 454
at Microsoft.FSharp.Control.AsyncPrimitives.QueueAsyncAndWaitForResultSynchronously[a](CancellationToken token, FSharpAsync`1 computation, FSharpOption`1 timeout) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 1140
at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronously[T](CancellationToken cancellationToken, FSharpAsync`1 computation, FSharpOption`1 timeout) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 1167
at Microsoft.FSharp.Control.FSharpAsync.RunSynchronously[T](FSharpAsync`1 computation, FSharpOption`1 timeout, FSharpOption`1 cancellationToken) in D:\a\_work\1\s\src\FSharp.Core\async.fs:line 1511
at <StartupCode$FSI_0003>.$FSI_0003.main@() in C:\Users\scyth\stdin:line 6
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
Stopped due to error
>
Using a global json with .NET6 seems to work though it might be something newly introduced in .NET7
PS C:\Users\scyth\repos\scripts> dotnet --version
6.0.304
PS C:\Users\scyth\repos\scripts> dotnet fsi
Microsoft (R) F# Interactive version 12.0.4.0 for F# 6.0
Copyright (c) Microsoft Corporation. All Rights Reserved.
For help type #help;;
> #r "nuget: FsHttp"
-
- open FsHttp
-
- http {
- POST "https://api.jspm.io/generate"
- body
- json ("""{
- "install": [ "lodash" ],
- "env": [ "browser", "module" ],
- "graph":true,
- "provider": "jspm"}""")
- }
- |> Request.send;;
[Loading C:\Users\scyth\AppData\Local\Temp\17468--537756bf-cf9e-42c5-acab-1d32703715f9\Project.fsproj.fsx]
namespace FSI_0002.Project
Binding session to 'C:/Users/scyth/.nuget/packages/fshttp/9.1.2/lib/net6.0/FsHttp.dll'...
val it: FsHttp.Domain.Response =
REQUEST
--------
POST https://api.jspm.io:443/generate HTTP/1.1
Cookie :
Content-Type : application/json
Content-Length : 108
===content===
{
"install": [ "lodash" ],
"env": [ "browser", "module" ],
"graph":true,
"provider": "jspm"}
RESPONSE
---------
HTTP/1.1 200 OK
Access-Control-Allow-Origin : *
Transfer-Encoding : chunked
Date : Mon, 03 Oct 2022 12:27:04 GMT
Server : Google, Frontend
Content-Type : application/json
===content===
{
"staticDeps": [
"https://ga.jspm.io/npm:[email protected]/lodash.js"
],
"dynamicDeps": [],
"map": {
"imports": {
"lodash": "https://ga.jspm.io/npm:[email protected]/lodash.js"
}
},
"graph": {
"https://ga.jspm.io/npm:[email protected]/": {
"lodash.js": {}
}
}
}
>
Thanks for the info. I'll investigate and see if that might be a bug in .Net 7 or if FsHttp is doing something wrong that might have been masked before...
Hi, I added a PR that should fix this issue.
Thanks for reporting the issue @AngelMunoz and fixing it @Samuel-Dufour :)
I've released and tested 10.0.0-preview2. See related PR and commits.
Hah I also hit this one just now
Yep, me too. 😄 This fix helped a lot!