美文网首页我爱编程
golang http发送文件

golang http发送文件

作者: Feng_Sir | 来源:发表于2018-06-20 09:12 被阅读0次
        w := multipart.NewWriter(body)
    
        content_type := w.FormDataContentType()
        w.WriteField("api_id", Appid)
        w.WriteField("api_secret", Key)
        w.WriteField("name", r.Name)
        w.WriteField("id_number", r.IdCode)
        dd, err := base64.StdEncoding.DecodeString(r.Photo)
        fmt.Println(len(dd))
        fmt.Println(err)
        file, err := w.CreateFormFile("selfie_file", "selfie_file")
        file.Write(dd)
        w.Close()
    
        tr := &http.Transport{
            TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
        }
        client := &http.Client{Transport: tr}
    
        request, _ := http.NewRequest("POST", RemoteUrl, body)
        request.Header.Set("Content-Type", content_type)
    
        rep, err := client.Do(request)
        if err != nil {
            log.Logger.Error(err.Error())
        }
        defer rep.Body.Close()
    
        bytes, _ := ioutil.ReadAll(rep.Body)```

    相关文章

      网友评论

        本文标题:golang http发送文件

        本文链接:https://www.haomeiwen.com/subject/btstyftx.html