-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.api.func.go
58 lines (53 loc) · 1.16 KB
/
example.api.func.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"fmt"
// "io/ioutil"
"log"
"net/http"
"net/http/cookiejar"
"net/url"
"crypto/tls"
)
const (
baseURL = "https://sandboxsdwan.cisco.com:8443"
)
var (
username = "devnetuser"
password = "Cisco123!"
)
type App struct {
Client *http.Client
}
type AuthenticityToken struct {
Token string
}
func (app *App) login() {
client := app.Client
loginURL := baseURL + "/j_security_check"
data := url.Values{
"j_username": {username},
"j_password": {password},
}
response, err := client.PostForm(loginURL, data)
if err != nil {
log.Fatal(err)
}
defer response.Body.Close()
fmt.Println("HTTP Response Status:", response.StatusCode, http.StatusText(response.StatusCode))
if response.StatusCode >= 200 && response.StatusCode <= 299 {
fmt.Println("HTTP Status is in the 2xx range")
} else {
fmt.Println("Argh! Broken")
}
}
func main() {
jar, _ := cookiejar.New(nil)
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
app := App{
Client: &http.Client{Jar: jar,Transport: tr},
}
app.login()
// client := app.Client
}