[Golang] 纯文本查看 复制代码 package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"strings"
)
func main() {
// 登录接口
loginURL := "https://passport.jd.com/new/login.aspx"
// 登录账号和密码
username := "your_username"//替换为自己的京东账号
password := "your_password"//替换为自己的京东密码
// 构造请求参数
data := url.Values{}
data.Set("username", username)
data.Set("password", password)
data.Set("uuid", "xxx")
data.Set("machineClient", "pc")
data.Set("eid", "xxx")
data.Set("fp", "xxx")
data.Set("_t", "xxx")
data.Set("loginType", "c")
// 发送POST请求
client := &http.Client{}
req, err := http.NewRequest("POST", loginURL, strings.NewReader(data.Encode()))
if err != nil {
fmt.Println(err)
return
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Referer", "https://www.jd.com/")
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36")
resp, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer resp.Body.Close()
// 处理响应结果
if resp.StatusCode == http.StatusOK {
fmt.Println("登录成功!")
// 输出京东商城主页的HTML代码
// bodyBytes, _ := ioutil.ReadAll(resp.Body)
// fmt.Println(string(bodyBytes))
} else {
fmt.Println("登录失败!")
// 输出错误信息
bodyBytes, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(bodyBytes))
}
} |