This repository has been archived by the owner on Dec 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
380 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package grab | ||
import ( | ||
"compress/flate" | ||
"compress/gzip" | ||
"fmt" | ||
"io" | ||
"log" | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/andybalholm/brotli" | ||
) | ||
|
||
// Do a post request using stored cookies and headers | ||
func doPOST(url string, data string) string { | ||
req, _ := http.NewRequest("POST", url, strings.NewReader(data)) | ||
//Add headers and cookies | ||
req.Header = Dataset.RequestInfo.Header | ||
req.Header.Set("Accept", "application/json, text/plain, */*") | ||
req.Header.Set("Accept-Encoding", "gzip, deflate, br") | ||
req.Header.Set("Content-Type", "application/json") | ||
req.Header.Set("Content-Length", fmt.Sprint(len(data))) | ||
req.Header.Set("Origin", "https://app.vocabgo.com") | ||
|
||
for i := 0; i < len(Dataset.RequestInfo.Cookies); i++ { | ||
req.AddCookie(Dataset.RequestInfo.Cookies[i]) | ||
} | ||
//Do request | ||
response, err := http.DefaultClient.Do(req) | ||
if err != nil { | ||
log.Println("[E]" + err.Error()) | ||
} | ||
defer response.Body.Close() | ||
read, _, _ := switchContentEncoding(response) | ||
raw, _ := io.ReadAll(read) | ||
return string(raw) | ||
} | ||
|
||
// Do a get request using stored cookies and headers | ||
func doGET(url string) string { | ||
req, _ := http.NewRequest("GET", url, nil) | ||
//Add headers and cookies | ||
req.Header = Dataset.RequestInfo.Header | ||
for i := 0; i < len(Dataset.RequestInfo.Cookies); i++ { | ||
req.AddCookie(Dataset.RequestInfo.Cookies[i]) | ||
} | ||
//Do request | ||
response, err := http.DefaultClient.Do(req) | ||
if err != nil { | ||
log.Println("[E]" + err.Error()) | ||
} | ||
defer response.Body.Close() | ||
read, _, _ := switchContentEncoding(response) | ||
raw, _ := io.ReadAll(read) | ||
return string(raw) | ||
} | ||
|
||
func switchContentEncoding(res *http.Response) (bodyReader io.Reader, encoder string, err error) { | ||
encoder = res.Header.Get("Content-Encoding") | ||
switch encoder { | ||
case "gzip": | ||
bodyReader, err = gzip.NewReader(res.Body) | ||
case "deflate": | ||
bodyReader = flate.NewReader(res.Body) | ||
case "br": | ||
bodyReader = brotli.NewReader(res.Body) | ||
default: | ||
bodyReader = res.Body | ||
} | ||
return | ||
} | ||
|
||
// Splits the salt and the valid JSON string | ||
func splitSalt(raw string) (salt string, validJSON string) { | ||
salt = raw[0:32] | ||
validJSON = raw[32:] | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.