@@ -59,8 +59,15 @@ func vsi(a, b int, f string, v ...interface{}) bool {
5959// do an HTTP request to a server and returns the response object and the
6060// complete response body. There's no need to close the response body as this
6161// 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+
6471 if err != nil {
6572 return nil , nil , err
6673 }
@@ -85,6 +92,7 @@ func do(method, host, ua, uri string) (*http.Response, []byte, error) {
8592
8693func main () {
8794 method := flag .String ("method" , "GET" , "Sets the HTTP method" )
95+ req_body := flag .String ("body" , "" , "Sets body data to send server" )
8896 host := flag .String ("host" , "" ,
8997 "Sets the Host header sent with both requests" )
9098 ignore := flag .String ("ignore" , "" ,
@@ -137,7 +145,7 @@ func main() {
137145 for i := 0 ; i < 2 ; i ++ {
138146 wg .Add (1 )
139147 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 ))
141149 wg .Done ()
142150 }(i )
143151 }
0 commit comments