@@ -98,20 +98,27 @@ func makeRequestLoop(url string, jsonBytes []byte) {
9898 i ++
9999 }
100100
101- response , _ , err := makeRequest (url , jsonBytes )
101+ request , err := http .NewRequest ("POST" , url , bytes .NewBuffer (jsonBytes ))
102+ if err != nil {
103+ fmt .Print ("\n " + debug .Sppg (err ))
104+ continue
105+ }
102106
107+ request .Header .Set ("Content-Type" , "application/json" )
108+ response , err := _client .Do (request )
103109 if err != nil {
104110 fmt .Print ("\n " + debug .Sppg (err ))
105111 continue
106112 }
107113
114+ body , bodyReadErr := ioutil .ReadAll (response .Body )
115+ response .Body .Close ()
116+
108117 if response .StatusCode != 200 {
109- bodyBytes , err := ioutil .ReadAll (response .Body )
110- response .Body .Close ()
111- if err == nil {
112- fmt .Printf ("\n status code: %d; body: %s\n " , response .StatusCode , string (bodyBytes ))
118+ if bodyReadErr == nil {
119+ fmt .Printf ("\n status code: %d; body: %s\n " , response .StatusCode , string (body ))
113120 } else {
114- fmt .Printf ("\n status code: %d; error reading body: %s\n " , response .StatusCode , string ( err .Error () ))
121+ fmt .Printf ("\n status code: %d; error reading body: %s\n " , response .StatusCode , bodyReadErr .Error ())
115122 }
116123 continue
117124 }
@@ -124,31 +131,6 @@ func makeRequestLoop(url string, jsonBytes []byte) {
124131 }
125132}
126133
127- func makeRequest (url string , jsonBytes []byte ) (* http.Response , string , error ) {
128- payload := bytes .NewBuffer (jsonBytes )
129-
130- request , err := http .NewRequest ("POST" , url , payload )
131- if err != nil {
132- return nil , "" , err
133- }
134-
135- request .Header .Set ("Content-Type" , "application/json" )
136-
137- response , err := _client .Do (request )
138- if err != nil {
139- return nil , "" , err
140- }
141-
142- defer response .Body .Close ()
143-
144- bodyBytes , err := ioutil .ReadAll (response .Body )
145- if err != nil {
146- return nil , "" , err
147- }
148-
149- return response , string (bodyBytes ), nil
150- }
151-
152134func mustReadJSONBytes (jsonPath string ) []byte {
153135 jsonBytes , err := files .ReadFileBytes (jsonPath )
154136 if err != nil {
0 commit comments