chromeworker/proxyserver/callback_test.go

52 lines
1.1 KiB
Go
Raw Normal View History

2020-11-19 11:05:32 +00:00
package main
import (
2020-11-20 07:30:52 +00:00
"io/ioutil"
2020-11-19 11:05:32 +00:00
"log"
2020-11-20 07:30:52 +00:00
"net/http"
"net/url"
2020-11-19 11:05:32 +00:00
"testing"
)
func TestCallback(t *testing.T) {
2020-11-20 07:30:52 +00:00
// eg := gin.New()
// eg.POST("/callback", func(c *gin.Context) {
// if tid, ok := c.GetPostForm("taskid"); ok {
// log.Println(tid)
// }
// })
http.HandleFunc("/callback", func(rw http.ResponseWriter, r *http.Request) {
tid := r.PostFormValue("taskid")
log.Println("tid: ", tid)
2020-11-19 11:05:32 +00:00
})
2020-11-20 07:30:52 +00:00
2020-11-19 11:05:32 +00:00
go func() {
2020-11-20 07:30:52 +00:00
data := url.Values{}
data["url"] = []string{"https://playerduo.com/api/playerDuo-service-v2/rip113?lang=en&deviceType=browser"}
data["callback"] = []string{"http://localhost:4848/callback"}
resp, err := http.DefaultClient.PostForm("http://localhost:7123/task/put", data)
2020-11-19 11:05:32 +00:00
if err != nil {
2020-11-20 07:30:52 +00:00
panic(err)
2020-11-19 11:05:32 +00:00
}
2020-11-20 07:30:52 +00:00
bodyRes, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
log.Println(string(bodyRes))
// resp, err := requests.NewSession().Post("http://localhost:7123/task/put").SetBodyAuto(data, requests.TypeFormData).Execute()
// if err != nil {
// log.Println(err)
// } else {
// log.Println(string(resp.Content()))
// }
2020-11-19 11:05:32 +00:00
}()
2020-11-20 07:30:52 +00:00
// eg.Run(":4848")
log.Fatal(http.ListenAndServe(":4848", nil))
2020-11-19 11:05:32 +00:00
}