golang 请求接口

// 调用 
func CallSearchFillingInfos(UA string,req *request.SearchDocRequest) response.SearchDocResponse {
	b, err := json.Marshal(req)
	FillingReq, _ := http.NewRequest(
		"POST",
		"https://www.XXX.com/data/api/FinancialNew/SearchFillingInfos",
		strings.NewReader(string(b)))
	// 设置user-agent
	FillingReq.Header.Set("User-Agent", UA)
	FillingReq.Header.Set("Content-Type","application/json")
	res, _ := (&http.Client{}).Do(FillingReq)
	defer res.Body.Close()
	body, err := ioutil.ReadAll(res.Body)
	if err != nil {
		fmt.Println("调用接口异常%v", err.Error())
	}
	var SearchDocResponse response.SearchDocResponse
	if err := json.Unmarshal(body, &SearchDocResponse); err != nil {
		fmt.Println("json解析错误:",err)
		return SearchDocResponse
	}
	return SearchDocResponse
}

  

posted @ 2020-07-23 14:04  小酥肉是我  阅读(611)  评论(0编辑  收藏  举报