I observed the following exception while attempting to troubleshoot my original question:
BadHttpRequestException: 'Bad chunk size data.'
Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException
HResult=0x80131620
Message=Bad chunk size data.
Source=Microsoft.AspNetCore.Server.Kestrel.Core
StackTrace:
at Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException.Throw(RequestRejectionReason reason)
The above exception occurred on my WebAPI controller.
Client:
let httpClient baseAddress =
let handler = new HttpClientHandler()
handler.AutomaticDecompression <- DecompressionMethods.GZip ||| DecompressionMethods.Deflate
let client = new HttpClient(handler)
client.Timeout <- TimeSpan(0,0,3)
client.BaseAddress <- Uri(baseAddress)
client.DefaultRequestHeaders.Accept.Clear()
client.DefaultRequestHeaders.Accept.Add(MediaTypeWithQualityHeaderValue("application/json"))
client
let postTo baseAddress (resource:string) (payload:Object) =
use client = httpClient baseAddress
let encoded = Uri.EscapeUriString(resource)
let result = client.PostAsJsonAsync(encoded, payload) |> toResult
result
Here's how it gets called:
let response = postTo AccountService.endPoint "register" applicant
Server:
open Microsoft.AspNetCore.Mvc
open Courier.Account.Language
open Courier.Account.Applicant
[<ApiController>]
[<Route("api/[controller]")>]
type RegisterController () =
inherit ControllerBase()
[<HttpPost>]
member x.Post([<FromBody>] applicant:Applicant) =
try
applicant
|> Post.application
|> function
| Error msg -> x.StatusCode(500, msg) :> IActionResult
| Ok result -> x.Ok(result) :> IActionResult
with
ex -> x.StatusCode(500, ex.Message) :> IActionResult
NOTE:
Many of my observations and troubleshooting results can be found on my original post.
Appendix:
[<CLIMutable>]
type Applicant = {
FirstName : string
LastName : string
Phone : string
Email : string
}
User contributions licensed under CC BY-SA 3.0