Files
Foundry-Scrapping-API/internal/foundry/requests/post_requests.go

39 lines
1.0 KiB
Go

package requests
import (
"bytes"
"fmt"
"net/http"
"net/url"
)
func (conf *Config) PostAuthenticationData() (*http.Response, error) {
authData := url.Values{}
authData.Add("adminPassword", conf.Password)
authData.Add("action", "adminAuth")
req, err := http.NewRequest("POST", fmt.Sprintf("http://%s%s", conf.Host, AuthPath), bytes.NewBuffer([]byte(authData.Encode())))
if err != nil {
return nil, err
}
header := http.Header{}
header.Set("Cookie", fmt.Sprintf("session=%s", conf.SessionID))
header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
header.Set("Connection", "keep-alive")
header.Set("Content-Length", fmt.Sprintf("%d", len(authData.Encode())))
header.Set("Content-Type", "application/x-www-form-urlencoded")
header.Set("Host", conf.Host)
header.Set("Origin", fmt.Sprintf("http://%s", conf.Host))
header.Set("Referer", fmt.Sprintf("http://%s%s", conf.Host, AuthPath))
req.Header = header
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
return resp, nil
}