Encode form values in gen_targets
This commit is contained in:
parent
7d3dbf1591
commit
4823379f42
3 changed files with 17 additions and 4 deletions
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
|
@ -9,6 +9,7 @@ import (
|
|||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
@ -63,13 +64,16 @@ func genPOSTResponseTargets(targetName string, conf *config) error {
|
|||
}
|
||||
|
||||
targets := make([]*vegeta.Target, 0)
|
||||
form := url.Values{}
|
||||
form.Set("Singleresponses.0", "32")
|
||||
// payload := "SingleResponses.0=32&SingleResponses.1=68&SingleResponses.2=34&SingleResponses.3=46&SingleResponses.4=25&SingleResponses.5=42&SingleResponses.6=7&SingleResponses.7=38&SingleResponses.8=13&SingleResponses.9=24&SingleResponses.10=73&SingleResponses.11=1&SingleResponses.12=19&SingleResponses.13=64&SingleResponses.14=80&SingleResponses.15=11&SingleResponses.16=70&SingleResponses.17=54&SingleResponses.18=50&SingleResponses.19=57"
|
||||
|
||||
for i, participant := range participants {
|
||||
targets = append(targets, &vegeta.Target{
|
||||
Method: "POST",
|
||||
URL: fmt.Sprintf("%s/responses/%d/update?format=html&tpl_content=responses_add_update&tpl_layout=base&update=true&login_session=%s", conf.Url, i+1, tokens[participant.FiscalCode]),
|
||||
Body: []byte(base64.StdEncoding.EncodeToString([]byte("PUNCH!"))),
|
||||
// Body: []byte(base64.StdEncoding.EncodeToString([]byte(payload))),
|
||||
Body: []byte(form.Encode()),
|
||||
Header: http.Header{"Content-Type": []string{"application/x-www-form-urlencoded"}},
|
||||
})
|
||||
}
|
||||
|
@ -85,11 +89,16 @@ func genPOSTResponseTargets(targetName string, conf *config) error {
|
|||
defer output.Close()
|
||||
|
||||
for _, t := range targets {
|
||||
jsonData, err := json.Marshal(t)
|
||||
var line string
|
||||
buf := bytes.NewBufferString(line)
|
||||
encoder := json.NewEncoder(buf)
|
||||
encoder.SetEscapeHTML(false)
|
||||
err := encoder.Encode(t)
|
||||
// jsonData, err := json.Marshal(t)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = output.WriteString(string(jsonData) + "\n\n")
|
||||
_, err = output.WriteString(buf.String() + "\n\n")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -374,6 +374,9 @@ func respondWithError(h *Handlers, w http.ResponseWriter, r *http.Request, err e
|
|||
if format == "" {
|
||||
format = renderer.GetContentFormat(r)
|
||||
}
|
||||
if h.Config.LogLevel > config.LOG_LEVEL_OFF {
|
||||
log.Println(err)
|
||||
}
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
h.Renderer[format].Render(w, r, h.CookieStore, err)
|
||||
}
|
||||
|
|
|
@ -233,6 +233,7 @@ func (model *Response) Update(db *Database, args map[string]string, w http.Respo
|
|||
return nil, errors.OutOfTime
|
||||
}
|
||||
|
||||
log.Println("Body", r.Form)
|
||||
err = renderer.Decode(response, r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
Loading…
Reference in a new issue