@@ -9,20 +9,20 @@ import (
9
9
"io/ioutil"
10
10
"net/http"
11
11
"os"
12
- "strconv"
13
12
14
13
flag "github.com/spf13/pflag"
15
14
"golang.org/x/text/encoding/simplifiedchinese"
16
15
"golang.org/x/text/transform"
17
16
)
18
17
19
18
const (
19
+ userAgent = "Mozilla/3.0 (compatible; Indy Library)"
20
20
urlCopywrite = "http://update.cz88.net/ip/copywrite.rar"
21
21
urlQqwryDat = "http://update.cz88.net/ip/qqwry.rar"
22
22
)
23
23
24
24
var (
25
- outputFile string
25
+ outputFile string
26
26
quiet , help bool
27
27
28
28
fileSize uint64
@@ -45,16 +45,13 @@ func (w *FetchWriter) progress() {
45
45
}
46
46
47
47
func fetch (key uint32 ) error {
48
- resp , err := http . Get (urlQqwryDat )
48
+ resp , err := newRequest (urlQqwryDat )
49
49
if err != nil {
50
50
return err
51
51
}
52
52
defer resp .Body .Close ()
53
- size , err := strconv .ParseUint (resp .Header .Get ("Content-Length" ), 10 , 32 )
54
- if err != nil {
55
- return err
56
- }
57
- if size != fileSize {
53
+
54
+ if uint64 (resp .ContentLength ) != fileSize {
58
55
return fmt .Errorf ("the file size of the agreement is different" )
59
56
}
60
57
@@ -113,7 +110,7 @@ func init() {
113
110
}
114
111
115
112
func main () {
116
- resp , err := http . Get (urlCopywrite )
113
+ resp , err := newRequest (urlCopywrite )
117
114
if err != nil {
118
115
fmt .Fprintf (os .Stderr , err .Error ())
119
116
os .Exit (1 )
@@ -137,6 +134,16 @@ func main() {
137
134
fatal (fetch (key ))
138
135
}
139
136
137
+ func newRequest (urls string ) (* http.Response , error ) {
138
+ req , err := http .NewRequest ("GET" , urls , nil )
139
+ if err != nil {
140
+ return nil , err
141
+ }
142
+ req .Header .Set ("User-Agent" , userAgent )
143
+ client := & http.Client {}
144
+ return client .Do (req )
145
+ }
146
+
140
147
func readVersion (p []byte ) []byte {
141
148
var start = 24
142
149
var end int
@@ -170,7 +177,7 @@ func toUTF8(s []byte) (b []byte) {
170
177
171
178
func fatal (err error ) {
172
179
if err != nil {
173
- fmt .Fprintf (os .Stderr , err .Error () + "\n " )
180
+ fmt .Fprintf (os .Stderr , err .Error ()+ "\n " )
174
181
os .Exit (1 )
175
182
}
176
183
}
0 commit comments