Could it maybe be that the esp code uses http? When put into the browser it uses https. If so I need to change WiFiClient to WiFiClientSecure. The code was originally designed with this.
When going to WiFiClientSecure the esp doesn't even connect to the host anymore though. The client.connect results in 0, which means the connection has failed. I fixed this issue by using http instead of https.