Sending payload in POST request in Vegeta with custom attacker
So I've seen several posts saying you're supposed to put the targets in a temp file and the body in a .json file, but I need to send lots of random data to my site, and ideally I don't want to be constantly writing new random data to these files --so I'd like to do it all in one file. If this is just impossible and I have to use multiple files, please let me know.
All I'm trying to do right now is send a POST request to a webpage that is simply a form with 4 inputs: title, number, volume, and year. I have the following code, but right now it's not sending values. It's sending a payload, but one that has no values. Meaning that a key and value "" keep getting stored in my map on the backend. Can anyone see the reason it's sending blanks? Could anyone tell me how I should go about fixing it?
package main
import (
"encoding/json"
"fmt"
"time"
vegeta "github.com/tsenart/vegeta/lib"
)
func NewCustomTargeter() vegeta.Targeter
return func(tgt *vegeta.Target) error
if tgt == nil
return vegeta.ErrNilTarget
tgt.Method = "POST"
tgt.URL = "http://localhost:8080/create.html"
payload := map[string]string
"title": "junk",
"number": "junk2",
"volume": "junk3",
"year": "junk4",
body, _ := json.Marshal(payload)
tgt.Body = byte(body)
return nil
func main()
rate := vegeta.RateFreq: 100, Per: 2 * time.Second
duration := 10 * time.Second
targeter := NewCustomTargeter()
attacker := vegeta.NewAttacker()
var metrics vegeta.Metrics
for res := range attacker.Attack(targeter, rate, duration, "Load Test")
metrics.Add(res)
metrics.Close()
fmt.Printf("%+v n", metrics)
json go post load-testing vegeta
add a comment |
So I've seen several posts saying you're supposed to put the targets in a temp file and the body in a .json file, but I need to send lots of random data to my site, and ideally I don't want to be constantly writing new random data to these files --so I'd like to do it all in one file. If this is just impossible and I have to use multiple files, please let me know.
All I'm trying to do right now is send a POST request to a webpage that is simply a form with 4 inputs: title, number, volume, and year. I have the following code, but right now it's not sending values. It's sending a payload, but one that has no values. Meaning that a key and value "" keep getting stored in my map on the backend. Can anyone see the reason it's sending blanks? Could anyone tell me how I should go about fixing it?
package main
import (
"encoding/json"
"fmt"
"time"
vegeta "github.com/tsenart/vegeta/lib"
)
func NewCustomTargeter() vegeta.Targeter
return func(tgt *vegeta.Target) error
if tgt == nil
return vegeta.ErrNilTarget
tgt.Method = "POST"
tgt.URL = "http://localhost:8080/create.html"
payload := map[string]string
"title": "junk",
"number": "junk2",
"volume": "junk3",
"year": "junk4",
body, _ := json.Marshal(payload)
tgt.Body = byte(body)
return nil
func main()
rate := vegeta.RateFreq: 100, Per: 2 * time.Second
duration := 10 * time.Second
targeter := NewCustomTargeter()
attacker := vegeta.NewAttacker()
var metrics vegeta.Metrics
for res := range attacker.Attack(targeter, rate, duration, "Load Test")
metrics.Add(res)
metrics.Close()
fmt.Printf("%+v n", metrics)
json go post load-testing vegeta
add a comment |
So I've seen several posts saying you're supposed to put the targets in a temp file and the body in a .json file, but I need to send lots of random data to my site, and ideally I don't want to be constantly writing new random data to these files --so I'd like to do it all in one file. If this is just impossible and I have to use multiple files, please let me know.
All I'm trying to do right now is send a POST request to a webpage that is simply a form with 4 inputs: title, number, volume, and year. I have the following code, but right now it's not sending values. It's sending a payload, but one that has no values. Meaning that a key and value "" keep getting stored in my map on the backend. Can anyone see the reason it's sending blanks? Could anyone tell me how I should go about fixing it?
package main
import (
"encoding/json"
"fmt"
"time"
vegeta "github.com/tsenart/vegeta/lib"
)
func NewCustomTargeter() vegeta.Targeter
return func(tgt *vegeta.Target) error
if tgt == nil
return vegeta.ErrNilTarget
tgt.Method = "POST"
tgt.URL = "http://localhost:8080/create.html"
payload := map[string]string
"title": "junk",
"number": "junk2",
"volume": "junk3",
"year": "junk4",
body, _ := json.Marshal(payload)
tgt.Body = byte(body)
return nil
func main()
rate := vegeta.RateFreq: 100, Per: 2 * time.Second
duration := 10 * time.Second
targeter := NewCustomTargeter()
attacker := vegeta.NewAttacker()
var metrics vegeta.Metrics
for res := range attacker.Attack(targeter, rate, duration, "Load Test")
metrics.Add(res)
metrics.Close()
fmt.Printf("%+v n", metrics)
json go post load-testing vegeta
So I've seen several posts saying you're supposed to put the targets in a temp file and the body in a .json file, but I need to send lots of random data to my site, and ideally I don't want to be constantly writing new random data to these files --so I'd like to do it all in one file. If this is just impossible and I have to use multiple files, please let me know.
All I'm trying to do right now is send a POST request to a webpage that is simply a form with 4 inputs: title, number, volume, and year. I have the following code, but right now it's not sending values. It's sending a payload, but one that has no values. Meaning that a key and value "" keep getting stored in my map on the backend. Can anyone see the reason it's sending blanks? Could anyone tell me how I should go about fixing it?
package main
import (
"encoding/json"
"fmt"
"time"
vegeta "github.com/tsenart/vegeta/lib"
)
func NewCustomTargeter() vegeta.Targeter
return func(tgt *vegeta.Target) error
if tgt == nil
return vegeta.ErrNilTarget
tgt.Method = "POST"
tgt.URL = "http://localhost:8080/create.html"
payload := map[string]string
"title": "junk",
"number": "junk2",
"volume": "junk3",
"year": "junk4",
body, _ := json.Marshal(payload)
tgt.Body = byte(body)
return nil
func main()
rate := vegeta.RateFreq: 100, Per: 2 * time.Second
duration := 10 * time.Second
targeter := NewCustomTargeter()
attacker := vegeta.NewAttacker()
var metrics vegeta.Metrics
for res := range attacker.Attack(targeter, rate, duration, "Load Test")
metrics.Add(res)
metrics.Close()
fmt.Printf("%+v n", metrics)
json go post load-testing vegeta
json go post load-testing vegeta
asked Nov 15 '18 at 4:11
r.rodriguezr.rodriguez
124
124
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You need to do few stuff to make attacker able to send data in FormData format.
First, set the Content-type header value to application/x-www-form-urlencoded. You might need to import net/http package.
header := http.Header
header.Set("Content-type", "application/x-www-form-urlencoded")
tgt.Header = header
Then, set put the data into url.Values format. Pass the encoded value of it into tgt.Body. You also need to import net/url package.
form := url.Values
form.Set("title", "junk")
form.Set("number", "junk2")
form.Set("volume", "junk3")
form.Set("year", "junk4")
tgt.Body = byte(form.Encode())
Additional notes
On the data preparation, we can also use map literal style.
But since url.Values is an alias of map[string]string (not map[string]string),
might need some adjustment.
form := url.Values
"title": string"junk",
"number": string"junk2",
"volume": string"junk3",
"year": string"junk4",
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53312321%2fsending-payload-in-post-request-in-vegeta-with-custom-attacker%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to do few stuff to make attacker able to send data in FormData format.
First, set the Content-type header value to application/x-www-form-urlencoded. You might need to import net/http package.
header := http.Header
header.Set("Content-type", "application/x-www-form-urlencoded")
tgt.Header = header
Then, set put the data into url.Values format. Pass the encoded value of it into tgt.Body. You also need to import net/url package.
form := url.Values
form.Set("title", "junk")
form.Set("number", "junk2")
form.Set("volume", "junk3")
form.Set("year", "junk4")
tgt.Body = byte(form.Encode())
Additional notes
On the data preparation, we can also use map literal style.
But since url.Values is an alias of map[string]string (not map[string]string),
might need some adjustment.
form := url.Values
"title": string"junk",
"number": string"junk2",
"volume": string"junk3",
"year": string"junk4",
add a comment |
You need to do few stuff to make attacker able to send data in FormData format.
First, set the Content-type header value to application/x-www-form-urlencoded. You might need to import net/http package.
header := http.Header
header.Set("Content-type", "application/x-www-form-urlencoded")
tgt.Header = header
Then, set put the data into url.Values format. Pass the encoded value of it into tgt.Body. You also need to import net/url package.
form := url.Values
form.Set("title", "junk")
form.Set("number", "junk2")
form.Set("volume", "junk3")
form.Set("year", "junk4")
tgt.Body = byte(form.Encode())
Additional notes
On the data preparation, we can also use map literal style.
But since url.Values is an alias of map[string]string (not map[string]string),
might need some adjustment.
form := url.Values
"title": string"junk",
"number": string"junk2",
"volume": string"junk3",
"year": string"junk4",
add a comment |
You need to do few stuff to make attacker able to send data in FormData format.
First, set the Content-type header value to application/x-www-form-urlencoded. You might need to import net/http package.
header := http.Header
header.Set("Content-type", "application/x-www-form-urlencoded")
tgt.Header = header
Then, set put the data into url.Values format. Pass the encoded value of it into tgt.Body. You also need to import net/url package.
form := url.Values
form.Set("title", "junk")
form.Set("number", "junk2")
form.Set("volume", "junk3")
form.Set("year", "junk4")
tgt.Body = byte(form.Encode())
Additional notes
On the data preparation, we can also use map literal style.
But since url.Values is an alias of map[string]string (not map[string]string),
might need some adjustment.
form := url.Values
"title": string"junk",
"number": string"junk2",
"volume": string"junk3",
"year": string"junk4",
You need to do few stuff to make attacker able to send data in FormData format.
First, set the Content-type header value to application/x-www-form-urlencoded. You might need to import net/http package.
header := http.Header
header.Set("Content-type", "application/x-www-form-urlencoded")
tgt.Header = header
Then, set put the data into url.Values format. Pass the encoded value of it into tgt.Body. You also need to import net/url package.
form := url.Values
form.Set("title", "junk")
form.Set("number", "junk2")
form.Set("volume", "junk3")
form.Set("year", "junk4")
tgt.Body = byte(form.Encode())
Additional notes
On the data preparation, we can also use map literal style.
But since url.Values is an alias of map[string]string (not map[string]string),
might need some adjustment.
form := url.Values
"title": string"junk",
"number": string"junk2",
"volume": string"junk3",
"year": string"junk4",
edited Nov 20 '18 at 7:39
answered Nov 15 '18 at 8:46
xparexpare
4,7072249
4,7072249
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53312321%2fsending-payload-in-post-request-in-vegeta-with-custom-attacker%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown