Hide this comment

This is strange, I copied your code into a new Self-Hosted Client-Server Application (I assume that's what you're using due to the port 9000) and I am not having this issue; I correctly receive "PostBody works!".

What version of WebSharper.Owin are you using? I'm on 3.6.14.133.

By on 4/24/2017 6:10 AM ()Reply
Hide this comment

I managed to find what was the issue. I illustrated it in this gist:

If you run it as it is, the POST with a JSON body won't work. However, if you comment lines 59, 60, and 61, it will work as expected.

I suspect the fact that we read the body prevents it from being used later, but not sure.

Do you have an idea why?

By on 4/27/2017 11:42 AM ()Reply
Hide this comment

Ah, right. Indeed, if the body stream has been read before WebSharper steps in, then it is not available anymore, and WebSharper sees an empty body. You need to copy the content into a MemoryStream so that it can be subsequently re-read:

1
2
3
4
5
6
7
8
9
if not environment.Request.Body.CanSeek then
    let s = new MemoryStream() :> Stream
    do! awaitTask <| environment.Request.Body.CopyToAsync s
    environment.Request.Body <- s
environment.Request.Body.Seek(0L, SeekOrigin.Begin) |> ignore

// Your 3 lines here...

environment.Request.Body.Seek(0L, SeekOrigin.Begin) |> ignore

And also, you need to place the whole body of the function inside the async block instead of before it (although I admit I don't completely understand why).

Here is my fixed version of your gist.

By on 5/1/2017 5:21 AM ()Reply
Hide this comment

Ah ok, it makes sense! Thanks for your help, I'll update my code accordingly.

By on 5/2/2017 2:54 AM ()Reply
Hide this comment

Hi Loic, you are right, I am using the Self-Hosted Client-Server Applicationa and WebSharper.Owin.3.6.14.133 too.. I'll try to set up a completely new, separate project and see if I still have the problem.

By on 4/26/2017 1:39 PM ()Reply
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper

Logging in...