-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.go.off
41 lines (34 loc) · 806 Bytes
/
test.go.off
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"fmt"
"io/ioutil"
"net/http"
"time"
)
func main() {
url := "https://fanyi-api.baidu.com/api/trans/vip/translate?q=hello&from=en&to=zh&appid=20220517001219044&salt=64143&sign=bd5a1af281e41f98b1739a0282ee00ce"
method := "POST"
timeout := time.Duration(5 * time.Second)
client := &http.Client{
Timeout: timeout,
}
req, err := http.NewRequest(method, url, nil)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Cookie", "BAIDUID=686D97BBF64B8829474597EA3006E5B8:FG=1")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}