IIS Express returns HTTP Error 400 after calling from Ubuntu WSL

I'm working on two web applications:

  • App1 is an application written in ASP.NET and runs directly on Windows 10. This application can be reached via browser at https://localhost:44311/
  • App2 is written in Django and runs in Ubuntu-20.04 through WSL2 on the same Windows computer. This application can be reached via browser at the address http://localhost:8000/

I am trying to make an https call from the App2's backend to the App1's backend. Disabling the Windows 10 firewall and reading another question it seems to me that the part correctly but App1 returns an error. I tried to execute the following instruction on the Ubuntu WSL shell:

curl -k https://DESKTOP-2MCFHIT.local:44311

But I get the following error:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request - Invalid Hostname</h2>
<hr><p>HTTP Error 400. The request hostname is invalid.</p>
</BODY></HTML>

It appears that IIS Express is unable to handle the request correctly due to not using "localhost". How can I solve?


Solution 1:

Taking an educated guess here since I don't use IIS Express, but it looks like from this SO question that the default for IIS Express is to bind to localhost only.

Since you need to access it from another "computer" (the virtualized WSL2 instance), you'll need it to listen on all addresses. In most software, this would be done by binding to 0.0.0.0:port, but it looks like the proper setting in IIS (from this answer to that question) is:

bindingInformation=":44311:"

Note that it also sounds like you'll need to run as Admin, if you aren't already doing so.