As @JimB commentator noted, executing a GET request with a body is not prohibited by the HTTP / 1.1 specification; however, it is also not required that the servers actually analyze the body, so do not be surprised if you encounter strange behavior.
So, here is how you will execute the GET request with the body using the golang HTTP client:
reader := strings.NewReader(`{"body":123}`) request, err := http.NewRequest("GET", "http://localhost:3030/foo", reader) // TODO: check err client := &http.Client{} resp, err := client.Do(request) // TODO: check err
The web server will see this request:
GET /foo HTTP/1.1 Host: localhost:3030 User-Agent: Go 1.1 package http Content-Length: 12 Accept-Encoding: gzip {"body":123}
To create a command line tool such as "curl", you will need to use several go packages (for example, to parse flags and process HTTP requests ), but presumably you can find what you need (excellent) docs for.
maerics
source share