Server responds with Bad Request

Hello everyone,

I got problems with this code: https://goplay.tools/snippet/WtyAy6eaZ66

When I’m trying to run this file with go run main.go localhost:8001, I’m getting dial tcp 127.0.0.1:8001: 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.

2 Likes

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

Ok, thanks. It’s working.