mirror of
https://github.com/fumiama/go-nd-portal.git
synced 2026-06-12 20:40:23 +08:00
drop fb
This commit is contained in:
@@ -11,7 +11,6 @@ import (
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/FloatTech/floatbox/web"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/fumiama/go-nd-portal/helper"
|
||||
@@ -48,7 +47,7 @@ func NewPortal(name, password string, ipv4 net.IP) (*Portal, error) {
|
||||
func (p *Portal) GetChallenge() (string, error) {
|
||||
u := fmt.Sprintf(PortalGetChallenge, "gondportal", url.QueryEscape(p.nam), p.ip, time.Now().UnixMilli())
|
||||
logrus.Debugln("GET", u)
|
||||
data, err := web.RequestDataWith(web.NewDefaultClient(), u, "GET", "", PortalHeaderUA)
|
||||
data, err := requestDataWith(u, "GET", PortalHeaderUA)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -80,7 +79,7 @@ func (p *Portal) Login(challenge string) error {
|
||||
hmd5 := p.PasswordHMd5(challenge)
|
||||
u := fmt.Sprintf(PortalLogin, "gondportal", url.QueryEscape(p.nam), hmd5, p.ip, p.CheckSum(challenge, hmd5, info), url.QueryEscape(info), time.Now().UnixMilli())
|
||||
logrus.Debugln("GET", u)
|
||||
data, err := web.RequestDataWith(web.NewDefaultClient(), u, "GET", "", PortalHeaderUA)
|
||||
data, err := requestDataWith(u, "GET", PortalHeaderUA)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
35
portal/web.go
Normal file
35
portal/web.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package portal
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var client = &http.Client{}
|
||||
|
||||
// requestDataWith 使用自定义请求头获取数据
|
||||
func requestDataWith(url, method, ua string) (data []byte, err error) {
|
||||
// 提交请求
|
||||
var request *http.Request
|
||||
request, err = http.NewRequest(method, url, nil)
|
||||
if err == nil {
|
||||
// 增加header选项
|
||||
if ua != "" {
|
||||
request.Header.Add("User-Agent", ua)
|
||||
}
|
||||
var response *http.Response
|
||||
response, err = client.Do(request)
|
||||
if err == nil {
|
||||
if response.StatusCode != http.StatusOK {
|
||||
s := fmt.Sprintf("status code: %d", response.StatusCode)
|
||||
err = errors.New(s)
|
||||
return
|
||||
}
|
||||
data, err = io.ReadAll(response.Body)
|
||||
response.Body.Close()
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user