我正在尝试使用REST Api从另一个应用程序获取数据。我可以登录并获取令牌值,但无法获取数据。
下面是我的代码:
func main() {
url := "https://******.***.****.**:***/api/jwt/login"
payload := strings.NewReader("username=****&password=****")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("content-type", "application/x-www-form-urlencoded")
req.Header.Add("cache-control", "no-cache")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
s := string(body)
fmt.Println(res)
fmt.Println(string(body))
var token = "AR-JWT "+s
url1 := "https://***.***.**.**:**/api/arsys/v1/entry/HPD:Help Desk/?q='Last Resolved Date' >= \"01/09/2018\"&fields=values(Incident Number,Customer Login ID,Last Resolved Date,Assigned Group)"
req1, _ := http.NewRequest(http.MethodGet, url1, nil)
req1.Header.Set("authorization", token)
req1.Header.Set("cache-control", "no-cache")
req1.Header.Set("Content-Type", "application/json")
res1, _ := http.DefaultClient.Do(req1)
defer res1.Body.Close()
body1, _ := ioutil.ReadAll(res1.Body)
fmt.Println(res1)
fmt.Println(string(body1))
}
我可以得到结果“ body”,而不是数据。错误如下:
&{400 Unknown Version 400 HTTP/1.1 1 1 map[Content-Length:[0]] 0xc04211c0c0 0 [] true false map[] 0xc042106100 0xc042180160}
谁能告诉我我要去哪里错了?