OkHttpClient 上传文件

OkHttpClient okHttpClient=new OkHttpClient();
MediaType parse = MediaType.parse("text/x-markdown;charset=utf-8");
File file = new File(Environment.getExternalStorageDirectory(),"note01.md");
Request builder=new Request.Builder()
        .post(RequestBody.create(parse,file))
        .url("https://api.github.com/markdown/raw")
        .build();
Call call = okHttpClient.newCall(builder);
call.enqueue(new Callback() {
    @Override
    public void onFailure(Call call, IOException e) {

    }

    @Override
    public void onResponse(Call call, Response response) throws IOException {
        Log.d("=======1111",response.body().string());
    }
});

你可能感兴趣的:(Android)