HTTP::Client.get uri on Windows

Hi there,

I’m working on building a simple little CLI program and ran into an issue on windows.

If I try to ‘crystal build’ on a file a with this function:

def download_hosts(uri)
  HTTP::Client.get uri do |response|
    File.open("hosts", "w") do |file|
      IO.copy response.body_io, file
    end
  end
end

Then I get the following error:
Error: undefined method 'get' for HTTP::Client.class

This works fine on Linux/Mac/BSD with crystal 1.5.0 and 1.5.1 but I ran into an issue on the windows 11 developer VM. Scoop currently has Crystal 1.5.0.

I know that windows is not fully supported. I see Coordinate porting to Windows #5430, however I’m not sure what to do to fix the issue - if I’m running into a user error or partial implementation issue.
If someone can point me in the right direction on what needs to be fixed, I’d be most appreciative!

Thanks!

HTTP::Client works on Windows. It just isn’t available in 1.5 upon requireing only "http". If you add an explicit require "http/client" the code should compile.

Alternatively, you can install crystal-nightly with scoop. Or wait for the 1.6 release which is scheduled for next week.

1 Like

Thanks! It compiles after adding require "http/client"!

Woohoo :star_struck:

Hey, separate question, what is the *.pdb file that gets created on windows?

Thank you!

1 Like