package clt_client

import (
	"github.com/sirupsen/logrus"
	"io/ioutil"
	"net/http"
)

func (c cltClient) SnapShot(url string) []byte {
	request, _ := http.NewRequest("get", url, nil)
	request.Header.Add("Accrpt", "image/png")
	resp, err := c.HttpClient.Do(request)
	if err != nil {
		logrus.Errorf("http错误:%v", err)
		return nil
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		logrus.Errorf("查询结果body读取错误:%v", err)
		return nil
	}
	return body
}

func (c cltClient) CommonGet(url string) ([]byte, error) {
	req, err := http.NewRequest("GET", url, nil)
	req.Header.Add("Accept", "application/json")
	resp, err := c.HttpClient.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	all, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}
	return all, nil
}
