feat: 添加请求
This commit is contained in:
1
go.mod
1
go.mod
@@ -48,6 +48,7 @@ require (
|
||||
github.com/felixge/httpsnoop v1.0.4 // indirect
|
||||
github.com/go-logr/logr v1.4.2 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/go-resty/resty/v2 v2.16.5 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.1 // indirect
|
||||
github.com/hashicorp/golang-lru v1.0.2 // indirect
|
||||
github.com/klauspost/compress v1.17.11 // indirect
|
||||
|
||||
2
go.sum
2
go.sum
@@ -39,6 +39,8 @@ github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/go-resty/resty/v2 v2.16.5 h1:hBKqmWrr7uRc3euHVqmh1HTHcKn99Smr7o5spptdhTM=
|
||||
github.com/go-resty/resty/v2 v2.16.5/go.mod h1:hkJtXbA2iKHzJheXYvQ8snQES5ZLGKMwQ07xAwp/fiA=
|
||||
github.com/go-sql-driver/mysql v1.9.1 h1:FrjNGn/BsJQjVRuSa8CBrM5BWA9BWoXXat3KrtSb/iI=
|
||||
github.com/go-sql-driver/mysql v1.9.1/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU=
|
||||
github.com/go-stomp/stomp/v3 v3.1.3 h1:5/wi+bI38O1Qkf2cc7Gjlw7N5beHMWB/BxpX+4p/MGI=
|
||||
|
||||
@@ -153,7 +153,7 @@ func (c *eggplantProductCode) channelTwo(ctx context.Context, forwardUrl *url.UR
|
||||
req := httplib.NewBeegoRequestWithCtx(ctx, "http://13.212.74.251:3767/pay", "POST").
|
||||
SetTransport(otelhttp.NewTransport(http.DefaultTransport)).
|
||||
SetTimeout(time.Second*30, time.Second*30).Retries(3).
|
||||
Header("Content-Type", "application/x-www-form-urlencoded")
|
||||
Header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8").Header("X-Requested-With", "XMLHttpRequest")
|
||||
|
||||
req.Param("order_no", forwardUrl.Query().Get("orderId"))
|
||||
req.Param("card_no", c.CardNo)
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package third_party
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/httplib"
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
func TestEggplantImpl_SendCard(t *testing.T) {
|
||||
@@ -18,21 +19,28 @@ func TestEggplantImpl_SendCard(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_eggplantProductCode_channelTwo(t *testing.T) {
|
||||
req := httplib.Post("https://httpbin.org/post")
|
||||
req.SetTimeout(time.Second*10, time.Second*10).Header("Content-Type", "multipart/form-data")
|
||||
// var b bytes.Buffer
|
||||
req.Param("order_no", "1234567890")
|
||||
req.Param("card_no", "1234567890")
|
||||
req.Param("pass", "1234567890")
|
||||
client := resty.New()
|
||||
|
||||
// body, err := req.String()
|
||||
// if err != nil {
|
||||
// t.Fatal(err)
|
||||
// }
|
||||
// logs.Info(body)
|
||||
// request := &netutil.HttpRequest{
|
||||
// RawURL: "https://jsonplaceholder.typicode.com/todos/1",
|
||||
// Method: "POST",
|
||||
// }
|
||||
// 构造 POST 请求
|
||||
resp, err := client.R().
|
||||
SetHeader("Accept", "application/json, text/javascript, */*; q=0.01").
|
||||
SetHeader("Accept-Language", "zh-CN,zh;q=0.9").
|
||||
SetHeader("Connection", "keep-alive").
|
||||
SetHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8").
|
||||
SetHeader("DNT", "1").
|
||||
SetHeader("Origin", "http://13.212.74.251:3767").
|
||||
SetHeader("Referer", "http://13.212.74.251:3767/pay?order_no=202504302358254336697293").
|
||||
SetHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36").
|
||||
SetHeader("X-Requested-With", "XMLHttpRequest").
|
||||
SetBody("order_no=202504302358254336697293&card_no=234234234&pass=23424234").
|
||||
Post("http://13.212.74.251:3767/pay")
|
||||
|
||||
// 错误检查
|
||||
if err != nil {
|
||||
log.Fatalf("Error sending request: %v", err)
|
||||
}
|
||||
|
||||
// 输出响应
|
||||
fmt.Println("Response Status Code:", resp.StatusCode())
|
||||
fmt.Println("Response Body:", resp.String())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user