@@ -59,8 +59,15 @@ func vsi(a, b int, f string, v ...interface{}) bool {
59
59
// do an HTTP request to a server and returns the response object and the
60
60
// complete response body. There's no need to close the response body as this
61
61
// will have been done.
62
- func do (method , host , ua , uri string ) (* http.Response , []byte , error ) {
63
- req , err := http .NewRequest (method , uri , nil )
62
+ func do (method , req_body , host , ua , uri string ) (* http.Response , []byte , error ) {
63
+ var err error
64
+ var req * http.Request
65
+ if strings .EqualFold ("POST" , method ) || strings .EqualFold ("PUT" , method ) {
66
+ req , err = http .NewRequest (method , uri , strings .NewReader (req_body ))
67
+ } else {
68
+ req , err = http .NewRequest (method , uri , nil )
69
+ }
70
+
64
71
if err != nil {
65
72
return nil , nil , err
66
73
}
@@ -85,6 +92,7 @@ func do(method, host, ua, uri string) (*http.Response, []byte, error) {
85
92
86
93
func main () {
87
94
method := flag .String ("method" , "GET" , "Sets the HTTP method" )
95
+ req_body := flag .String ("body" , "" , "Sets body data to send server" )
88
96
host := flag .String ("host" , "" ,
89
97
"Sets the Host header sent with both requests" )
90
98
ignore := flag .String ("ignore" , "" ,
@@ -137,7 +145,7 @@ func main() {
137
145
for i := 0 ; i < 2 ; i ++ {
138
146
wg .Add (1 )
139
147
go func (i int ) {
140
- resp [i ], body [i ], err [i ] = do (* method , * host , * ua , flag .Arg (i ))
148
+ resp [i ], body [i ], err [i ] = do (* method , * req_body , * host , * ua , flag .Arg (i ))
141
149
wg .Done ()
142
150
}(i )
143
151
}
0 commit comments