Server responds with Bad Request

Hello everyone,

I got problems with this code:

When I’m trying to run this file with go run main.go localhost:8001, I’m getting dial tcp connect: connection refused.

It works when I run on port 80: go run main.go localhost:80

After that when I type something in the prompt and press Enter I’m getting ->: HTTP/1.1 400 Bad Request error. I can’t figure out what’s the problem.

I will be grateful for any suggestions.

This program connects to the TCP hostname and port that you give it and sends and receives messages. Do you have a server listening for the connection? I don’t have anything running on port 8001 on my computer, so I get the same message.


I’ve used netstat on port 8001
Here’s what I got:

Ok, thanks. It’s working.