@@ -15,20 +15,26 @@ func updateDNSPod(client network.Client, domain, host, token string, ip net.IP)
1515 if ip == nil {
1616 return fmt .Errorf ("IP address was not given to updater" )
1717 }
18- body := bytes .NewBufferString (url.Values {
19- "login_token" : []string {token },
20- "format" : []string {"json" },
21- "domain" : []string {domain },
22- "length" : []string {"200" },
23- "sub_domain" : []string {host },
24- "record_type" : []string {"A" },
25- }.Encode ())
26- req , err := http .NewRequest (http .MethodPost , "https://dnsapi.cn/Record.List" , body )
18+ u := url.URL {
19+ Scheme : "https" ,
20+ Host : "dnsapi.cn" ,
21+ Path : "/Record.List" ,
22+ }
23+ values := url.Values {}
24+ values .Set ("login_token" , token )
25+ values .Set ("format" , "json" )
26+ values .Set ("domain" , domain )
27+ values .Set ("length" , "200" )
28+ values .Set ("sub_domain" , host )
29+ values .Set ("record_type" , "A" )
30+ u .RawQuery = values .Encode ()
31+ r , err := http .NewRequest (http .MethodPost , u .String (), bytes .NewBufferString (values .Encode ()))
2732 if err != nil {
2833 return err
2934 }
30- req .Header .Set ("Content-Type" , "application/x-www-form-urlencoded" )
31- status , content , err := client .DoHTTPRequest (req )
35+ r .Header .Set ("Content-Type" , "application/x-www-form-urlencoded" )
36+ r .
Header .
Set (
"User-Agent" ,
"DDNS-Updater [email protected] " )
37+ status , content , err := client .DoHTTPRequest (r )
3238 if err != nil {
3339 return err
3440 } else if status != http .StatusOK {
@@ -61,21 +67,24 @@ func updateDNSPod(client network.Client, domain, host, token string, ip net.IP)
6167 if len (recordID ) == 0 {
6268 return fmt .Errorf ("record not found" )
6369 }
64- body = bytes .NewBufferString (url.Values {
65- "login_token" : []string {token },
66- "format" : []string {"json" },
67- "domain" : []string {domain },
68- "record_id" : []string {recordID },
69- "value" : []string {ip .String ()},
70- "record_line" : []string {recordLine },
71- "sub_domain" : []string {host },
72- }.Encode ())
73- req , err = http .NewRequest (http .MethodPost , "https://dnsapi.cn/Record.Ddns" , body )
70+
71+ u .Path = "/Record.Ddns"
72+ values = url.Values {}
73+ values .Set ("login_token" , token )
74+ values .Set ("format" , "json" )
75+ values .Set ("domain" , domain )
76+ values .Set ("record_id" , recordID )
77+ values .Set ("value" , ip .String ())
78+ values .Set ("record_line" , recordLine )
79+ values .Set ("sub_domain" , host )
80+ u .RawQuery = values .Encode ()
81+ r , err = http .NewRequest (http .MethodPost , u .String (), bytes .NewBufferString (values .Encode ()))
7482 if err != nil {
7583 return err
7684 }
77- req .Header .Set ("Content-Type" , "application/x-www-form-urlencoded" )
78- status , content , err = client .DoHTTPRequest (req )
85+ r .Header .Set ("Content-Type" , "application/x-www-form-urlencoded" )
86+ r .
Header .
Set (
"User-Agent" ,
"DDNS-Updater [email protected] " )
87+ status , content , err = client .DoHTTPRequest (r )
7988 if err != nil {
8089 return err
8190 } else if status != http .StatusOK {
0 commit comments