Send form-urlencoded with cURL in Go
Paste a curl command that sends form-urlencoded and get idiomatic Go code. We pick the right serialization for net/http and set the correct Content-Type.
Quick answer
To convert a cURL command to Go, paste it into the Toolpaper workbench below. It parses the command in your browser and emits idiomatic Go code — headers, query string, request body, authentication (Bearer, Basic, API key), and cookies are all wired up automatically. No data is uploaded; conversion is fully client-side.
Prefer a different target? See the full cURL to Go reference, or jump to the same guide in JavaScript, Node.js, or Python.
package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
client := &http.Client{CheckRedirect: func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse }}
body := strings.NewReader("username=ada&password=lovelace")
req, _ := http.NewRequest("POST", "https://api.example.com/login", body)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err := client.Do(req)
if err != nil { panic(err) }
defer resp.Body.Close()
out, _ := io.ReadAll(resp.Body)
fmt.Println(string(out))
}Example
A representative curl command for this scenario. Paste your own above to convert an exact match.
curl -X POST https://api.example.com/login \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=ada&password=lovelace"Implementation notes
- Content-Type is detected from -H headers first, then inferred from the body shape when the header is missing.
- application/x-www-form-urlencoded bodies are decoded into structured pairs so net/http owns the encoding — you never double-encode a value.
- Charset directives on Content-Type (e.g. application/json; charset=utf-8) survive the round trip.
Common mistakes
- Setting Content-Type manually and then also using net/http's helper — you end up with duplicate headers or the wrong one wins.
- Mixing form encoding with JSON headers — the server rejects with 400 and it's easy to miss in code review.
- Trusting the browser DevTools "Copy as cURL" to preserve charset — it often drops it. Clean panel restores common defaults.
Common questions
- How is form-urlencoded encoded in the generated Go?
- application/x-www-form-urlencoded bodies map to the right primitive in each language — data= in Python, url.Values in Go, FormUrlEncodedContent in C#.
- Does it preserve Content-Type?
- Yes. The Content-Type header is honored and matched against the body so serialization stays consistent.
- Is anything uploaded?
- No. Parsing and generation happen entirely in your browser.
More payload types in Go
Go hub →The same guide in other languages
All guides →In JavaScript
/how-to/send-form-with-curl-in-javascript
In Node.js
/how-to/send-form-with-curl-in-node
In Python
/how-to/send-form-with-curl-in-python
In PHP
/how-to/send-form-with-curl-in-php
In Ruby
/how-to/send-form-with-curl-in-ruby
In Rust
/how-to/send-form-with-curl-in-rust
In Java
/how-to/send-form-with-curl-in-java
In Kotlin
/how-to/send-form-with-curl-in-kotlin
Full Go reference on the cURL to Go hub, or open the main converter for all 18 targets.