zoukankan      html  css  js  c++  java
  • Android 使用okhtth上传图片multipart/formdata

    自己整这个问题整了半天,写篇博客记录下
    private void uploadMultiFile() {
    String imageType = "multipart/form-data";
    File file = new File(imgUrl);imgUrl为图片位置
    RequestBody fileBody = RequestBody.create(MediaType.parse("image/jpg"), file);
    RequestBody requestBody = new MultipartBody.Builder()
    .setType(MultipartBody.FORM)
    .addFormDataPart("file", "head_image", fileBody)
    .addFormDataPart("imagetype", imageType)
    .build();
    Request request = new Request.Builder()
    .url(url)
    .post(requestBody)
    .build();
    final okhttp3.OkHttpClient.Builder httpBuilder = new OkHttpClient.Builder();
    OkHttpClient okHttpClient = httpBuilder
    .build();
    okHttpClient.newCall(request).enqueue(new Callback() {
    @Override
    public void onFailure(Request request, IOException e) {

    }

    @Override
    public void onResponse(Response response) throws IOException {
    String htmlStr = response.body().string();
    Log.i("result", htmlStr);

    }
    });
    }
  • 相关阅读:
    swagger生成接口文档
    二分查找通用模板
    go-json技巧
    【Go】获取用户真实的ip地址
    数据库储存时间类型
    密码加密:md5/sha1 +盐值
    参数里时间格式的转换
    不好定位的元素定位
    vim编辑器
    ps -ef | grep php kill -9
  • 原文地址:https://www.cnblogs.com/gznuhaoge/p/5874042.html
Copyright © 2011-2022 走看看