OkHttp4 写法kotlin版本：import okhttp3.MediaType.Companion.toMediaType import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.RequestBody.Companion.asRequestBody //String转RequestBody String、ByteArray、ByteString都可以用toRequestBody() val stringBody ="body参数".toRequestBody("application/json;charset=utf-8".toMediaType()) val request:Request=Request .Builder() .post(stringBody) .build() //File转RequestBody val file=File("") val fileBody=file.asRequestBody("text/x-markdown; charset=utf-8".toMediaType()) val request = MultipartBody.Builder() .addFormDataPart("file", file.name,fileBody) .build()java版本:import okhttp3.MediaType.Companion.*; import okhttp3.RequestBody.Companion.*; //String转RequestBody String、ByteArray、ByteString都可以用toRequestBody() MediaType mediaType=MediaType.Companion.parse("application/json;charset=utf-8"); RequestBody stringBody=RequestBody.Companion.create("body参数",mediaType); Request request=new Request .Builder() .post(stringBody) .build(); //File转RequestBody MediaType mediaType=MediaType.Companion.parse("text/x-markdown; charset=utf-8"); File file=new File(""); RequestBody fileBody=RequestBody.Companion.create(file,mediaType); Request request=new MultipartBody.Builder() .addFormDataPart("file", file.getName(),fileBody) .build();4.0之前写法:val request:Request=Request .Builder() .post(RequestBody.create(MediaType.parse("application/json;charset=utf-8"),"body参数")) .build()编译器提示如下：又是一个小技巧
过滤语法package:mine：默认语法package:my-package-ID：根据包名过滤tag:my-tag：根据tag过滤level:ERROR：根据日志等级过滤-tag:exclude-this-tag：在前面添加-，排除指定的tagtag~:regex-tag：在后面添加~，支持正则过滤-tag~:exclude-this-regex-tag：支持正则过滤排除指定TAG-package:exclude-this-package：同上package~:regex-package：同上-package~:exclude-this-regex-package：同上回退版本Settings-> Experimental -> [x] Enable new Logcat tool window 取消选择 -> 重启 Android Studio