读取某变量的值
package main import (
"fmt"
"net/http"
"io/ioutil"
) func main() { url := "http://127.0.0.1:39321/iotgateway/read?ids=Channel1.Device1.tag1,Channel1.Device1.tag2" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Connection", "keep-alive")
req.Header.Add("Cache-Control", "max-age=0")
req.Header.Add("Upgrade-Insecure-Requests", "1")
req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36")
req.Header.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8")
req.Header.Add("Accept-Encoding", "gzip, deflate, br")
req.Header.Add("Accept-Language", "zh-CN,zh;q=0.9")
req.Header.Add("cache-control", "no-cache") res, _ := http.DefaultClient.Do(req) defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body) fmt.Println(res)
fmt.Println(string(body)) }