diff options
| -rw-r--r-- | go.mod | 2 | ||||
| -rw-r--r-- | go.sum | 2 | ||||
| -rw-r--r-- | main.go | 29 |
3 files changed, 28 insertions, 5 deletions
| @@ -1,3 +1,5 @@ | |||
| 1 | module codeberg.org/flpolyaplus/aplus | 1 | module codeberg.org/flpolyaplus/aplus |
| 2 | 2 | ||
| 3 | go 1.21.3 | 3 | go 1.21.3 |
| 4 | |||
| 5 | require golang.org/x/net v0.18.0 // indirect | ||
| @@ -0,0 +1,2 @@ | |||
| 1 | golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= | ||
| 2 | golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= | ||
| @@ -4,17 +4,28 @@ import ( | |||
| 4 | "fmt" | 4 | "fmt" |
| 5 | "io" | 5 | "io" |
| 6 | "net/http" | 6 | "net/http" |
| 7 | "net/http/cookiejar" | ||
| 8 | "strings" | ||
| 9 | |||
| 10 | "golang.org/x/net/publicsuffix" | ||
| 7 | ) | 11 | ) |
| 8 | 12 | ||
| 9 | var base_link string | 13 | var base_link string |
| 10 | var token string | 14 | var token string |
| 11 | 15 | ||
| 12 | func main() { | 16 | func main() { |
| 17 | |||
| 18 | jar, _ := cookiejar.New(&cookiejar.Options{ | ||
| 19 | PublicSuffixList: publicsuffix.List, | ||
| 20 | }) | ||
| 21 | |||
| 13 | client := http.Client{ | 22 | client := http.Client{ |
| 14 | CheckRedirect: func(req *http.Request, via []*http.Request) error { | 23 | CheckRedirect: func(req *http.Request, via []*http.Request) error { |
| 15 | fmt.Println("Redirected to:", req.URL) | 24 | fmt.Println("Redirected to:", req.URL) |
| 25 | fmt.Println(req.Cookies()) | ||
| 16 | return nil | 26 | return nil |
| 17 | }, | 27 | }, |
| 28 | Jar: jar, | ||
| 18 | } | 29 | } |
| 19 | 30 | ||
| 20 | initialize() | 31 | initialize() |
| @@ -43,23 +54,31 @@ func main() { | |||
| 43 | fmt.Printf("%s: %s\n", key, values) | 54 | fmt.Printf("%s: %s\n", key, values) |
| 44 | } | 55 | } |
| 45 | 56 | ||
| 46 | req, err := client.PostForm("https://floridapoly.aplusattendance.com/canvas", form_values) | 57 | //req, _ := client.PostForm("https://floridapoly.aplusattendance.com/canvas", form_values) |
| 58 | req, _ := http.NewRequest(http.MethodPost, "https://floridapoly.aplusattendance.com/canvas", strings.NewReader(form_values.Encode())) | ||
| 59 | req.Header.Set("Content-Type", "application/x-www-form-urlencoded") | ||
| 60 | req.Header.Set("Access-Control-Allow-Origin", "*") | ||
| 61 | req.Header.Set("Access-Control-Allow-Credentials", "true") | ||
| 62 | req.Header.Set("Access-Control-Allow-Headers", "Content-Type,access-control-allow-origin, access-control-allow-headers,access-control-allow-credentials") | ||
| 63 | |||
| 64 | resp, err = client.Do(req) | ||
| 47 | 65 | ||
| 48 | if err != nil { | 66 | if err != nil { |
| 49 | fmt.Println("Error posting form to Aplus Attendance.") | 67 | fmt.Println("Error posting form to Aplus Attendance.") |
| 50 | } | 68 | } |
| 51 | 69 | ||
| 52 | body, err = io.ReadAll(req.Body) | 70 | body, err = io.ReadAll(resp.Body) |
| 53 | 71 | ||
| 54 | if err != nil { | 72 | if err != nil { |
| 55 | fmt.Println("Error reading body of post form response from aplus attendance.") | 73 | fmt.Println("Error reading body of post form response from aplus attendance.") |
| 56 | } | 74 | } |
| 57 | 75 | ||
| 58 | fmt.Println(string(body)) | 76 | fmt.Println(string(body)) |
| 59 | fmt.Println(req) | 77 | //fmt.Println(resp) |
| 60 | 78 | fmt.Println(resp.Header) | |
| 79 | fmt.Println(resp.Cookies()) | ||
| 61 | // we need to submit the above post request correctly in order to submit this request. | 80 | // we need to submit the above post request correctly in order to submit this request. |
| 62 | //resp, _ = client.Get("https://floridapoly.aplusattendance.com/canvas/student/?canvasCourse=7329&doStudentAuth=true") | 81 | //resp, _ = client.Get("https://floridapoly.aplusattendance.com/canvas/student/?canvasCourse=7329&doStudentAuth=truee") |
| 63 | //body, _ = io.ReadAll(resp.Body) | 82 | //body, _ = io.ReadAll(resp.Body) |
| 64 | 83 | ||
| 65 | //fmt.Println(string(body)) | 84 | //fmt.Println(string(body)) |
