This code is correct, however it seems you’ve hit a bug in the compiler. Please can you report the bug on the issue tracker along with your compiler and OS version.
On 20/02/17 03:23, Кир Кур wrote:
Hi,--
I receive json api requests from third-party. How can I get the data? I'm really sorry, there are no problem for me to get it from HTTP response, but here I'm stack for a day already.
server = HTTP::Server.new("0.0.0.0", 8080) do |context|
if body = context.request.body
data = JSON.parse(body)
end
context.response.content_type = "text/plain"
context.response.print data
end
puts "Listening on http://0.0.0.0:8080"
server.listen
And it gives me this output:
Bug: trying to downcast (JSON::Any | Nil) <- JSON::Any
0x55694e: ??? at ??
0x12ee86f: ??? at ??
0x135dc89: ??? at ??
0x130de2c: ??? at ??
0x133dded: ??? at ??
0x130e92c: ??? at ??
0x130ecb2: ??? at ??
0x132cea4: ??? at ??
0x1317301: ??? at ??
0x133e45b: ??? at ??
0x130e92c: ??? at ??
0x133406f: ??? at ??
0x130f471: ??? at ??
0x130ecb2: ??? at ??
0x12bb66b: ??? at ??
0x1b6b5f5: ??? at ??
0x5ab46b: ??? at ??
0x57ba4d: main at ??
0x7f6f972c8830: __libc_start_main at ??
0x556271: ??? at ??
Error: you've found a bug in the Crystal compiler. Please open an issue, including source code that will allow us to reproduce the bug: https://github.com/crystal-lang/crystal/issues
How to do it? Thanks.
You received this message because you are subscribed to the Google Groups "Crystal" group.
To unsubscribe from this group and stop receiving emails from it, send an email to crystal-lang...@googlegroups.com.
To post to this group, send email to crysta...@googlegroups.com.
Visit this group at https://groups.google.com/group/crystal-lang.
To view this discussion on the web visit https://groups.google.com/d/msgid/crystal-lang/024eed88-3e87-4b35-b55c-aff7bbfb313d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
body = context.request.body.not_nil!.gets_to_end