NancyFx / Nancy

Lightweight, low-ceremony, framework for building HTTP based services on .Net and Mono
http://nancyfx.org
MIT License
7.15k stars 1.47k forks source link

AJAX JSON String Post to Nancy Function Vb.net #2923

Closed ajp-sourceship closed 5 years ago

ajp-sourceship commented 5 years ago

Hello All,

I have inherited a Project from another developer. Its a Web App written in VB.net and has Nancy (Not Sure what version). I have a c# background and little VB experience and never have touched Nancy.

I have a web page that allows me to paste images from a clipboard to attach them into an email. I take the images convert it to a base64 string, and put that into an js array. I was attempting to post the data into a function in my VB code but I keep on getting an empty DynamicDictionary.

image

image

image I am passing it in as an Object but when I mouse over it, it shows up as a Nancy.DynamicDictionary with nothing inside.

How can I have this come in as the raw JSON String instead of a Nancy.DynamicDictionary? I've tried this to no avail (Get Error 500 in chrome debugger): image

Also, I apologize if this is the wrong place to ask questions, I work alone and have been staring at this for too many hours now. The room has no windows.

khellang commented 5 years ago

Have you looked at https://github.com/NancyFx/Nancy/wiki/Taking-a-look-at-the-DynamicDictionary and https://github.com/NancyFx/Nancy/wiki/Model-binding?

Sorry I can't be more helpful, on the phone.

khellang commented 5 years ago

Just read that last part

The room has no windows.

😂🤣

Zaid-Ajaj commented 5 years ago

@sourceship I am not sure what the syntax is in VB but you should not be looking into the p parameter because it is just the route path data, not the request body. In your function CaptureFullImage you can access Me.Request.Body which is a Stream that you can read:

Dim reader as StreamReader = new StreamReader(Me.Request.Body)
Dim bodyContentAsJson as String = reader.ReadToEnd()

again, I am not sure the syntax is correct but I hope you get the idea

ajp-sourceship commented 5 years ago

@khellang and @Zaid-Ajaj Thank You So Much for your help!

Zaid The code you left was spot on in VB, was able to get the data from within my array. I really appreciate both of you, this was the small thing holding me up yesterday.

Thanks again guys! Wish you all the best!