前言:
眼前同学们对“formdata contenttype”大致比较重视,姐妹们都需要知道一些“formdata contenttype”的相关文章。那么小编同时在网摘上收集了一些关于“formdata contenttype””的相关资讯,希望朋友们能喜欢,各位老铁们快快来学习一下吧!发送告警消息
func QY_Wechat_SendMessage(accessToken string, req *SendMessageReq) (rsp *SendMessageRsp, err error) { var resp *http.Response var bytes []byte rsp = &SendMessageRsp{} body, _ := json.Marshal(req) url := sendMessageUrl + "access_token=" + accessToken if resp, err = http.Post(url, "application/json", strings.NewReader(string(body))); err != nil { return } if bytes, err = ioutil.ReadAll(resp.Body); err != nil { return } json.Unmarshal(bytes, &rsp) if rsp.Errmsg != "ok" { err = errors.New(rsp.Errmsg) return } fmt.Println("token info: " + helper.StuToJson(rsp)) return}
媒体文件上传
func QY_Wechat_MediaUpload(accessToken string, mediaType, fileName string, body []byte) (rsp *MediaUploadRsp, err error) { var ( req *http.Request resp *http.Response requestBodyStr string bodyStr string ) var bytes []byte dc := http.DefaultClient rsp = &MediaUploadRsp{} buf := &bytes2.Buffer{} writer := multipart.NewWriter(buf) fw, err := writer.CreateFormFile("media", fileName) if err != nil { return } _, err = fw.Write(body) url := mediaUploadUrl + "access_token=" + accessToken + "&type=" + mediaType writer.Close() if req, err = http.NewRequest("POST", url, buf); err != nil { return } req.Header.Add("Content-Type", writer.FormDataContentType()) if resp, err = dc.Do(req); err != nil { return } if bytes, err = ioutil.ReadAll(resp.Body); err != nil { return } json.Unmarshal(bytes, &rsp) if rsp.Errmsg != "ok" { err = errors.New(rsp.Errmsg) return } fmt.Println("token info: " + helper.StuToJson(rsp)) return}
版权声明:
本站文章均来自互联网搜集,如有侵犯您的权益,请联系我们删除,谢谢。
标签: #formdata contenttype