In Go http package, how to get query string in POST request?
Hello everyone! I recently started learning Go and encountered a problem while working with an HTTP server. I need to handle a POST request where the client passes parameters both in the query string (URL) and in the request body (form-data).
Here's an example of my code:
```go
func handlePost(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
// Trying to get parameters from query string
name := r.URL.Query().Get("name")
age := r.URL.Query().Get("age")
// And from the request body
r.ParseForm()
email := r.FormValue("email")
log.Printf("Name: %s, Age: %s, Email: %s", name, age, email)
}
```
The problem is that when I send a POST re
No answers yet.
Log in to leave an answer
Blogs
Error Handling in TypeScript: try/catch and Advanced Methods
Caching in JavaScript: Redis, Memcached, and Built-in Solutions for Node.js
How to Write a REST API in Go in 30 Minutes: A Practical Guide
CLI utilities in Rust: how to write your first tool in an evening