我该如何解决:BadHttpRequestException:“坏块大小数据”。

时间:2019-10-28 17:37:28

标签: android f# asp.net-core-webapi

在尝试对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)

上述异常发生在我的WebAPI控制器上。

客户

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

这里是怎么称呼的:

let response = postTo AccountService.endPoint "register" applicant

服务器:

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

注意:

我的original post中可以找到我的许多观察结果和故障排除结果。

附录:

[<CLIMutable>]
type Applicant = {
    FirstName : string
    LastName  : string
    Phone     : string
    Email     : string
}

0 个答案:

没有答案