作个记录,直接上代码:
RequestBody requestBody = new MultipartBuilder().type(MultipartBuilder.FORM) .addFormDataPart("deadline", String.valueOf(System.currentTimeMillis() / 1000 + 60)) .addFormDataPart("Token", "你的相册对应生成的Token") .addFormDataPart("file", "test", RequestBody.create(MediaType.parse("image/*"), img)).build(); Request request = new Request.Builder(). url("http://up.imgapi.com/") .post(requestBody) .build(); OkHttpClient client = new OkHttpClient(); client.newCall(request).enqueue(new Callback() { @Override public void onFailure(Request request, IOException e) { System.out.println("error:" +e.getMessage()); } @Override public void onResponse(Response response) throws IOException { System.out.println("onResponse:" + response.code() + ",msg:"+response.message()); if (response.isSuccessful()) { ResponseBody body = response.body(); if (body != null) { System.out.println("success:" + body.string()); } } } });