Skip to content

Commit ba0fd70

Browse files
committed
fix post https data
1 parent 704b404 commit ba0fd70

File tree

4 files changed

+40
-25
lines changed

4 files changed

+40
-25
lines changed

bomb.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func main(){
1818

1919
utils.LoadDatas()
2020
forever := make(chan struct{})
21-
go utils.ReshapeData()
21+
utils.ReshapeData()
2222
go core.StartBomb()
2323
<- forever
2424
}

core/core.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,24 @@ import (
1212

1313
func StartBomb(){
1414
for _, api := range conf.Datas {
15-
go bomb(*api)
15+
go bomb(api)
1616
}
1717
}
1818

1919

20-
func bomb(api models.API) {
20+
func bomb(api *models.API) {
2121
u, err := url.Parse(api.Url)
2222
if err != nil {
2323
fmt.Printf("bomb %s url is invalid, will not use this!\n", api.Url)
2424
return
2525
}
2626
sender := NewSender(u.Scheme)
27-
sender.Run(api)
27+
sender.Run(*api)
2828
gap := api.Gap + cmd.Delay
2929
for {
3030
time.Sleep(time.Duration(gap)* time.Second)
3131
fmt.Printf("bomb %s with %s\n", cmd.Phone, api.Name)
32-
sender.Run(api)
32+
//sender.Run(api)
3333
}
3434
}
3535

core/sender.go

+35-18
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,40 @@ import (
66
"strings"
77
"net/http"
88
"io/ioutil"
9-
// "crypto/tls"
9+
"crypto/tls"
1010

1111
"bomb/models"
1212
)
1313

1414
type Send struct {}
1515

1616
type HttpSender struct {
17-
*Send
17+
Send
1818
}
1919

2020
type HttpsSender struct {
21-
*Send
21+
Send
2222
}
2323

2424
type TcpSender struct {
25-
*Send
25+
Send
2626
}
2727

2828
func (s Send) Init () {
2929
// TODO
3030
}
3131

32-
func (s *Send) SendData (api models.API) {
33-
fmt.Println(api.Url)
34-
// TODO
35-
}
32+
//func (s *Send) SendData (api models.API) {
33+
// fmt.Println(api.Url)
34+
// // TODO
35+
//}
3636

3737
func (s Send) Recv () {
3838
//TODO
3939
}
4040

4141
func (s *Send) Run (api models.API) {
42-
s.SendData(api)
42+
// s.SendData(api)
4343
}
4444

4545

@@ -61,7 +61,6 @@ func NewSender(way string) models.Sender {
6161

6262

6363
func (h *HttpSender) SendData (api models.API) {
64-
fmt.Println("************************")
6564
switch api.Method {
6665
case 0: {
6766
if len(api.Headers) <= 0 {
@@ -71,7 +70,7 @@ func (h *HttpSender) SendData (api models.API) {
7170
} else {
7271
defer resp.Body.Close()
7372
body, _ := ioutil.ReadAll(resp.Body)
74-
fmt.Println(resp.Status, body)
73+
fmt.Println(resp.Status, string(body))
7574
}
7675
} else {
7776
client := http.Client{}
@@ -94,7 +93,7 @@ func (h *HttpSender) SendData (api models.API) {
9493
if err == nil {
9594
defer resp.Body.Close()
9695
body, _ := ioutil.ReadAll(resp.Body)
97-
fmt.Println(resp.Status, body)
96+
fmt.Println(resp.Status, string(body))
9897
}
9998
}
10099
}
@@ -115,7 +114,7 @@ func (h *HttpSender) SendData (api models.API) {
115114
if err == nil {
116115
defer resp.Body.Close()
117116
body, _ := ioutil.ReadAll(resp.Body)
118-
fmt.Println(resp.Status, body)
117+
fmt.Println(resp.Status, string(body))
119118
}
120119
}
121120
}
@@ -143,14 +142,17 @@ func (h *HttpsSender) SendData (api models.API) {
143142
if err == nil {
144143
defer resp.Body.Close()
145144
body, _ := ioutil.ReadAll(resp.Body)
146-
fmt.Println(resp.Status, body)
145+
fmt.Println(resp.Status, string(body))
147146
}
148147
}
149148
}
150149
case 1: {
151-
tr := &http.Transport{}
150+
tr := &http.Transport{
151+
TLSClientConfig:&tls.Config{InsecureSkipVerify: true},
152+
}
152153
client := &http.Client{Transport: tr}
153-
req, err := http.NewRequest("POST", api.Url, nil)
154+
body := []byte(api.Data)
155+
req, err := http.NewRequest("POST", api.Url, bytes.NewBuffer(body))
154156
if err != nil {
155157
fmt.Printf("%v", err)
156158
} else {
@@ -163,12 +165,27 @@ func (h *HttpsSender) SendData (api models.API) {
163165
if err == nil {
164166
defer resp.Body.Close()
165167
body, _ := ioutil.ReadAll(resp.Body)
166-
fmt.Println(resp.Status, body)
168+
fmt.Println(resp.Status, string(body))
167169
}
168170
}
169171
}
170172
case 2: {
171-
//
173+
// TODO
172174
}
173175
}
174176
}
177+
178+
func (h *HttpsSender) Init () {}
179+
func (h *HttpsSender) Recv () {}
180+
func (h *HttpsSender) Run (api models.API) {
181+
h.SendData(api)
182+
}
183+
func (h *HttpSender) Run (api models.API) {
184+
h.SendData(api)
185+
}
186+
187+
func (t *TcpSender) SendData (api models.API) {
188+
fmt.Println(api.Url)
189+
// TODO
190+
}
191+

utils/utils.go

-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,5 @@ func ReshapeData() {
4848
}
4949
api.Data = strings.ReplaceAll(api.Data, "<phone>", cmd.Phone)
5050
api.Url = strings.ReplaceAll(api.Url, "<phone>", cmd.Phone)
51-
fmt.Println(api)
5251
}
53-
fmt.Printf("%v\n", conf.Datas)
5452
}

0 commit comments

Comments
 (0)