diff --git a/go.mod b/go.mod index a5570a0..10fe00c 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module codeberg.org/flpolyaplus/aplus go 1.21.3 + +require golang.org/x/net v0.18.0 // indirect diff --git a/go.sum b/go.sum index e69de29..ee9cb73 100644 --- a/go.sum +++ b/go.sum @@ -0,0 +1,2 @@ +golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= +golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= diff --git a/main.go b/main.go index 0480117..473b027 100644 --- a/main.go +++ b/main.go @@ -4,17 +4,28 @@ import ( "fmt" "io" "net/http" + "net/http/cookiejar" + "strings" + + "golang.org/x/net/publicsuffix" ) var base_link string var token string func main() { + + jar, _ := cookiejar.New(&cookiejar.Options{ + PublicSuffixList: publicsuffix.List, + }) + client := http.Client{ CheckRedirect: func(req *http.Request, via []*http.Request) error { fmt.Println("Redirected to:", req.URL) + fmt.Println(req.Cookies()) return nil }, + Jar: jar, } initialize() @@ -43,23 +54,31 @@ func main() { fmt.Printf("%s: %s\n", key, values) } - req, err := client.PostForm("https://floridapoly.aplusattendance.com/canvas", form_values) + //req, _ := client.PostForm("https://floridapoly.aplusattendance.com/canvas", form_values) + req, _ := http.NewRequest(http.MethodPost, "https://floridapoly.aplusattendance.com/canvas", strings.NewReader(form_values.Encode())) + req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + req.Header.Set("Access-Control-Allow-Origin", "*") + req.Header.Set("Access-Control-Allow-Credentials", "true") + req.Header.Set("Access-Control-Allow-Headers", "Content-Type,access-control-allow-origin, access-control-allow-headers,access-control-allow-credentials") + + resp, err = client.Do(req) if err != nil { fmt.Println("Error posting form to Aplus Attendance.") } - body, err = io.ReadAll(req.Body) + body, err = io.ReadAll(resp.Body) if err != nil { fmt.Println("Error reading body of post form response from aplus attendance.") } fmt.Println(string(body)) - fmt.Println(req) - + //fmt.Println(resp) + fmt.Println(resp.Header) + fmt.Println(resp.Cookies()) // we need to submit the above post request correctly in order to submit this request. - //resp, _ = client.Get("https://floridapoly.aplusattendance.com/canvas/student/?canvasCourse=7329&doStudentAuth=true") + //resp, _ = client.Get("https://floridapoly.aplusattendance.com/canvas/student/?canvasCourse=7329&doStudentAuth=truee") //body, _ = io.ReadAll(resp.Body) //fmt.Println(string(body))