strings.NewReader用法

使用http.Post方法,三个参数,第三个参数body类型io.Reader。

strings.NewReader() 字节

 

 

func main()  {
    cists := []string{"北京","武汉"}
    for _, c := range cists {
       
        c_name := fmt.Sprintf("cname=&pid=&keyword=%s&pageIndex=1&pageSize=50",c)
        resp,_ :=http.Post(
            "http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=keyword",
            "application/x-www-form-urlencoded",
            strings.NewReader(c_name),
        )
        body,_ := ioutil.ReadAll(resp.Body)
        fmt.Println(string(body))
        resp.Body.Close()
    }
   
}
posted @ 2022-06-22 17:37  WH迪诺  阅读(841)  评论(0)    收藏  举报