如何为okhttp3添加请求记录(包括标头)?

时间:2019-01-23 13:40:15

标签: okhttp3

我使用:

com.squareup.okhttp3:okhttp:3.12.1

此处是由okhttp3创建http请求的Koltin代码。

import okhttp3.*

const val REST_API_ENDPOINT_URL = " https://tradesatoshi.com"
const val REQUEST_NEGOTIATE_BASE = REST_API_ENDPOINT_URL + "/signalr/negotiate"

    val negotiateURL = REQUEST_NEGOTIATE_BASE + "?clientProtocol=1.5&connectionData=$connectionData"
                val requestNegotiate = Request.Builder()
                        .url(negotiateURL)
                        .header("referer", "https://tradesatoshi.com/Exchange/?market=DOGE-BTC")
                        .build()
                оkHttpClient.newCall(requestNegotiate).enqueue(object : Callback {
                    override fun onResponse(call: Call, response: Response) {
                    val responseBody = response.body()
            }


        Here log:



    15:30:02.824 [OkHttp https://tradesatoshi.com/...] INFO TradesatoshiSocketListener - negotiateURL =  https://tradesatoshi.com/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22chat%22%7D%2C%7B%22name%22%3A%22notification%22%7D%5D
15:30:02.913 [OkHttp https://tradesatoshi.com/...] INFO TradesatoshiSocketListener - responseBodyJson = {"Url":"/signalr","LongPollDelay":0.0}
15:30:02.914 [OkHttp https://tradesatoshi.com/...] INFO TradesatoshiSocketListener - -> success received connectionToken -> create webSocket request

您可以记录http请求(包括标头)

如何为oktth3做到这一点?

0 个答案:

没有答案