Closed Riven-Spell closed 1 year ago
You need to listen to as many messages as may arrive. Your receive
gets the first message on the socket, which is the adventofcode.com header exchanging some HTTP/2 protocol messages with the connection. The response is in the next message. This works:
{:ok, conn} = Mint.HTTP.connect(:https, "adventofcode.com", 443)
{:ok, conn, req_ref} = Mint.HTTP.request(conn, "GET", "/2021/day/24/input", [], nil)
msg = receive do: (msg -> msg)
{:ok, conn, []} = Mint.HTTP.stream(conn, msg)
msg = receive do: (msg -> msg)
{:ok, conn, responses} = Mint.HTTP.stream(conn, msg)
dbg(responses)
You can see examples of receiving messages recursively in the Mint documentation: https://hexdocs.pm/mint/1.4.2/architecture.html#usage-examples
I added a warning to the docs for Mint.HTTP.stream/2
. Hopefully it will help call out attention to this 🙃
I get the feeling I'm doing something tremendously dumb, but I just cannot figure it out for the life of me.
The following code returns the following information:
Why is nothing returned whatsoever?