-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.go
50 lines (46 loc) · 1.04 KB
/
test.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
package main
import (
"fmt"
"net/url"
"net/http"
"io/ioutil"
"log"
"unicode/utf8"
"github.com/qiniu/iconv"
)
func main() {
cd, err := iconv.Open("utf-8", "gbk") // convert utf-8 to gbk
if err != nil {
fmt.Println("iconv.Open failed!")
return
}
defer cd.Close()
u, _ := url.Parse("http://qt.gtimg.cn/q=r_hk00700")
q := u.Query()
// q.Set("username", "user")
// q.Set("password", "passwd")
u.RawQuery = q.Encode()
res, err := http.Get(u.String());
if err != nil {
log.Fatal(err)
return;
}
result, err := ioutil.ReadAll(res.Body)
res.Body.Close()
if err != nil {
log.Fatal(err)
return;
}
result := cd.ConvString(result)
fmt.Printf("%s", result)
// u, _ := url.Parse("http://qt.gtimg.cn/q=r_hk00700")
// q := u.Query()
// u.RawQuery =q.Encode()
// res, err := http.Get(u.String())
// result, err := ioutil.ReadAll(res.Body)
// res.Body.Close()
// fmt.Printf("%s", result)
// // q := u.Query()
// // log(u)
// fmt.Println("Hello, 世界")
}