add cookie and x-csrf-token

This commit is contained in:
one.cat 2021-09-08 16:02:53 +08:00
parent d8dd7d54ea
commit 31c9e5da5a
5 changed files with 58 additions and 1 deletions

6
api.go
View file

@ -33,6 +33,12 @@ func (s *Scraper) RequestAPI(req *http.Request, target interface{}) error {
req.Header.Set("Authorization", "Bearer "+bearerToken)
req.Header.Set("X-Guest-Token", s.guestToken)
// use cookie
if len(s.Cookie) > 0 && len(s.XCsrfToken) > 0 {
req.Header.Set("Cookie", s.Cookie)
req.Header.Set("x-csrf-token", s.XCsrfToken)
}
resp, err := s.client.Do(req)
if err != nil {
return err