80,348
社区成员
发帖
与我相关
我的任务
分享
File file = new File(filePath);
RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("deadline", String.valueOf(System.currentTimeMillis() / 1000 + 60))
.addFormDataPart("aid", "aid")
.addFormDataPart("Token", "token")
.addFormDataPart("file", file.getName(),RequestBody.create(MediaType.parse("image/*"), file)).build();
Request request = new Request.Builder()
url("http://up.imgapi.com/")
.post(requestBody)
.build();
OkHttpClient client = new OkHttpClient.Builder().build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
System.out.println("error:" +e.getMessage());
}
@Override
public void onResponse(Call call, 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());
}
}
}
});