예제 #1
0
파일: main.go 프로젝트: mengjinglei/tools
func get(cmd, action, url string) (ret []byte, err error) {

	client := &http.Client{}
	log.Info(">>>>>>> "+cmd, "url", url)
	req, err := http.NewRequest(action, url, nil)
	if err != nil {
		log.Error(err)
	}

	req.Header.Set("Authorization", "QiniuStub uid=1&ut=4")

	resp, err := client.Do(req)
	if err != nil {
		log.Error(err)
	}

	defer resp.Body.Close()

	_bytes, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Error(err)
	}
	log.Println(resp.StatusCode, resp.Status, string(_bytes))

	ret = _bytes
	return
}
예제 #2
0
파일: main.go 프로젝트: mengjinglei/tools
func post(cmd, url string, dat []byte) (ret []byte, err error) {

	client := &http.Client{}
	log.Info(">>>>>>> "+cmd, "url", url)
	req, err := http.NewRequest("POST", url, strings.NewReader(string(dat)))
	if err != nil {
		log.Error(err)
	}

	req.Header.Set("Authorization", "QiniuStub uid=1&ut=4")
	req.Header.Set("Content-Type", "text/plain")
	resp, err := client.Do(req)
	if err != nil {
		log.Error(err)
	}

	defer resp.Body.Close()

	_bytes, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Error(err)
	}
	log.Println(resp.StatusCode, resp.Status, string(_bytes))

	ret = _bytes
	return
}