tsenart / vegeta

HTTP load testing tool and library. It's over 9000!
http://godoc.org/github.com/tsenart/vegeta/lib
MIT License
23.51k stars 1.36k forks source link

Example of using headers for vegeta library #523

Closed saefullohmaslul closed 4 years ago

saefullohmaslul commented 4 years ago

Question

is there an example of using vegeta as a library that requires certain headers to send POST requests?

When sending POST we use the following code:

targeter := vegeta.NewStaticTargeter(vegeta.Target{
  Method: "POST",
  URL:    "http://localhost:9100/endpoint",
})

How to add the header?

saefullohmaslul commented 4 years ago

Solved.

I'm using this code:

payload := map[string]string{
  "body": "body",
}
body, _ := json.Marshal(payload)
header := http.Header{}
header.Set("content-type", "application/json")

targeter := vegeta.NewStaticTargeter(vegeta.Target{
  Method: "POST",
  URL:    "http://localhost:9100/endpoint",
  Header: header,
  Body: []byte(body)
})