okhttp3.RequestBody 的请求报文
时间: 2023-08-17 21:13:01 浏览: 301
根据引用\[1\]和引用\[3\]中的内容,可以使用以下方法获取okhttp3.RequestBody的请求报文:
1. 首先,将RequestBody转换成String。可以使用以下方法将RequestBody转换成String:
```kotlin
private fun bodyToString(body: RequestBody): String {
val buffer = Buffer()
body.writeTo(buffer)
return buffer.readString(Charset.defaultCharset())
}
```
2. 然后,可以使用以下方法获取常规post请求参数的内容:
```kotlin
private fun getParamContent(body: RequestBody): String {
val buffer = Buffer()
body.writeTo(buffer)
return buffer.readUtf8()
}
```
通过以上两个方法,你可以获取到okhttp3.RequestBody的请求报文。
#### 引用[.reference_title]
- *1* *2* [OKHttp3网络请求,接口处理](https://blog.csdn.net/zhijiandedaima/article/details/120347205)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [OkHttp请求request转换成字符串的顺序问题解决方案](https://blog.csdn.net/T_yoo_csdn/article/details/82382935)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文