mirror of
https://github.com/taigrr/godns
synced 2025-01-18 04:03:25 -08:00
add post func
This commit is contained in:
parent
06dd9a89a5
commit
8d0c8e624c
@ -4,6 +4,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetCurrentIP(url string) (string, error) {
|
func GetCurrentIP(url string) (string, error) {
|
||||||
@ -18,3 +20,38 @@ func GetCurrentIP(url string) (string, error) {
|
|||||||
body, _ := ioutil.ReadAll(response.Body)
|
body, _ := ioutil.ReadAll(response.Body)
|
||||||
return string(body), nil
|
return string(body), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func generate_header(content url.Values, setting Settings) url.Values {
|
||||||
|
header := url.Values{}
|
||||||
|
header.Add("login_email", setting.Email)
|
||||||
|
header.Add("login_password", setting.Password)
|
||||||
|
header.Add("format", "json")
|
||||||
|
header.Add("lang", "en")
|
||||||
|
header.Add("error_on_empty", "no")
|
||||||
|
|
||||||
|
for k, _ := range content {
|
||||||
|
header.Add(k, content.Get(k))
|
||||||
|
}
|
||||||
|
|
||||||
|
return header
|
||||||
|
}
|
||||||
|
|
||||||
|
func post_data(url string, content url.Values, setting Settings) (string, error) {
|
||||||
|
client := &http.Client{}
|
||||||
|
req, _ := http.NewRequest("POST", "https://dnsapi.cn"+url, strings.NewReader(content.Encode()))
|
||||||
|
|
||||||
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
req.Header.Set("User-Agent", fmt.Sprintf("GoDNS/0.1 (%s)", setting.Email))
|
||||||
|
|
||||||
|
response, err := client.Do(req)
|
||||||
|
defer response.Body.Close()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Post failed...")
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, _ := ioutil.ReadAll(response.Body)
|
||||||
|
|
||||||
|
return string(resp), nil
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user