当前位置: 首页 > news >正文

怎么编写自己的网站图片版小说网站源码

怎么编写自己的网站,图片版小说网站源码,哪些电影网站怎么建设的,游戏代理免费加盟目录 一、前情回顾二、HttpLoggingInterceptor1、HttpLoggingInterceptor拦截器是做什么的?2、如何使用HttpLoggingInterceptor?2.1 日志级别2.2 如何看日志?2.2.1 日志级别:BODY2.2.2 日志级别:BASIC2.2.3 日志级别&a…

目录

  • 一、前情回顾
  • 二、HttpLoggingInterceptor
    • 1、HttpLoggingInterceptor拦截器是做什么的?
    • 2、如何使用HttpLoggingInterceptor?
      • 2.1 日志级别
      • 2.2 如何看日志?
        • 2.2.1 日志级别:BODY
        • 2.2.2 日志级别:BASIC
        • 2.2.3 日志级别:HEADERS
        • 2.2.4 日志级别:NONE

一、前情回顾

  • 在“认识并使用OkHttp3”中提到“OkHttp的拦截器也要学习下~”,这篇文章就来学习下HttpLoggingInterceptor这个拦截器。

二、HttpLoggingInterceptor

1、HttpLoggingInterceptor拦截器是做什么的?

  • HttpLoggingInterceptor是OkHttp3提供的一个拦截器,主要用于记录HTTP请求和响应的详细信息,包括请求的URL、方法、头部信息,以及响应的状态码、响应体等内容。(下文会结合具体例子,详细说明)

2、如何使用HttpLoggingInterceptor?

  • 代码示例:
// 创建日志拦截器实例并设置日志级别
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(Level.BODY);// 创建OkHttpClient并添加拦截器
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(logging).build();

2.1 日志级别

  • HttpLoggingInterceptor允许指定日志的级别,来控制需要记录的详细程度,包括:

    • NONE:不记录任何日志。
    • BASIC:记录请求类型、URL、响应状态码以及响应时间。
    • HEADERS:记录请求和响应的头部信息,以及BASIC级别的信息。
    • BODY:记录请求和响应的头部信息、body内容,以及BASIC级别的信息。注意,记录body内容可能会消耗资源,并且会读取body数据,这可能会影响请求的执行。
  • 这其实对应的就是请求/响应的三部分。

    • 请求
      • 请求行
      • 请求头(Header)
      • 请求体 (Body)
    • 响应
      • 状态行
      • 响应头
      • 响应体

2.2 如何看日志?

2.2.1 日志级别:BODY
  • 示例
二月 17, 2024 9:04:42 下午 okhttp3.internal.platform.Platform log
信息: --> POST https://api.openai.com/v1/chat/completions
二月 17, 2024 9:04:42 下午 okhttp3.internal.platform.Platform log
信息: Content-Type: application/json; charset=utf-8
二月 17, 2024 9:04:42 下午 okhttp3.internal.platform.Platform log
信息: Content-Length: 197
二月 17, 2024 9:04:42 下午 okhttp3.internal.platform.Platform log
信息: Authorization: Bearer xxx
二月 17, 2024 9:04:42 下午 okhttp3.internal.platform.Platform log
信息: 
二月 17, 2024 9:04:42 下午 okhttp3.internal.platform.Platform log
信息: {"messages":[{"content":"1 + 1 = ?","role":"user"}],"model":"gpt-3.5-turbo-0613","n":1,"stream":false,"temperature":1.0,"frequency_penalty":0.0,"max_tokens":2048,"presence_penalty":0.0,"top_p":1.0}
二月 17, 2024 9:04:42 下午 okhttp3.internal.platform.Platform log
信息: --> END POST (197-byte body)
二月 17, 2024 9:04:43 下午 okhttp3.internal.platform.Platform log
信息: <-- 200 https://api.openai.com/v1/chat/completions (1599ms)
二月 17, 2024 9:04:43 下午 okhttp3.internal.platform.Platform log
信息: date: Sat, 17 Feb 2024 13:04:43 GMT
二月 17, 2024 9:04:43 下午 okhttp3.internal.platform.Platform log
信息: content-type: application/json
......
二月 17, 2024 9:04:43 下午 okhttp3.internal.platform.Platform log
信息: 
二月 17, 2024 9:04:43 下午 okhttp3.internal.platform.Platform log
信息: {"id": "chatcmpl-8tEexggs1EAHChI6OAhJAIyqCVjxg","object": "chat.completion","created": 1708175083,"model": "gpt-3.5-turbo-0613","choices": [{"index": 0,"message": {"role": "assistant","content": "1 + 1 = 2"},"logprobs": null,"finish_reason": "stop"}],"usage": {"prompt_tokens": 13,"completion_tokens": 7,"total_tokens": 20},"system_fingerprint": null
}二月 17, 2024 9:04:43 下午 okhttp3.internal.platform.Platform log
信息: <-- END HTTP (458-byte body)
2.2.2 日志级别:BASIC
  • 示例
二月 17, 2024 9:52:49 下午 okhttp3.internal.platform.Platform log
信息: --> POST https://api.openai.com/v1/chat/completions (197-byte body)
二月 17, 2024 9:52:51 下午 okhttp3.internal.platform.Platform log
信息: <-- 200 https://api.openai.com/v1/chat/completions (1879ms, unknown-length body)
2.2.3 日志级别:HEADERS
  • 示例
二月 17, 2024 9:54:37 下午 okhttp3.internal.platform.Platform log
信息: --> POST https://api.openai.com/v1/chat/completions
二月 17, 2024 9:54:37 下午 okhttp3.internal.platform.Platform log
信息: Content-Type: application/json; charset=utf-8
二月 17, 2024 9:54:37 下午 okhttp3.internal.platform.Platform log
信息: Content-Length: 197
二月 17, 2024 9:54:37 下午 okhttp3.internal.platform.Platform log
信息: Authorization: Bearer xxx
二月 17, 2024 9:54:37 下午 okhttp3.internal.platform.Platform log
信息: --> END POST
二月 17, 2024 9:54:39 下午 okhttp3.internal.platform.Platform log
信息: <-- 200 https://api.openai.com/v1/chat/completions (1756ms)
二月 17, 2024 9:54:39 下午 okhttp3.internal.platform.Platform log
信息: date: Sat, 17 Feb 2024 13:54:39 GMT
二月 17, 2024 9:54:39 下午 okhttp3.internal.platform.Platform log
信息: content-type: application/json
...
二月 17, 2024 9:54:39 下午 okhttp3.internal.platform.Platform log
信息: <-- END HTTP
2.2.4 日志级别:NONE
  • 没有任何的日志。那还不如别添加这个拦截器。

从调试和监控HTTP调用的角度,我会选日志级别BODY。

http://www.yayakq.cn/news/781018/

相关文章:

  • 做 网站 技术支持 抓获 互助省直部门门户网站建设
  • 建立网站加强家园沟通和联系的利弊手机优化软件哪个好
  • 沈阳网站关键词优化公司绍兴专门做网站的公司
  • 毕业设计是做网站设计手机主题制作网站
  • 自己做的网站如何上传个人公司网页如何设计
  • 动易网站管理系统下载人社系统网站一体化建设方案
  • 怎么建立一个网站开展业务制作简历网站开发
  • 做网站除了广告还有什么收入的微信开发商
  • 搜一搜站长工具wordpress 打不开
  • 公司网站怎么发布文章国内最好的危机公关公司
  • seo学习网站建网站用什么软件好
  • 团购网站开发语言免费招聘网站有哪些
  • 购物网站建设 费用wordpress难用
  • 网站备案后会被注销吗手机做直播官方网站
  • 我想做服装网站怎么做自己做物流网站
  • 网站增值服务Dedecms手机网站源码
  • 免费的个人简历模板下载东莞网络优化排名
  • 有关小城镇建设的网站信主网站
  • 微网站建设招聘如何经营电商平台
  • windows 2003建设网站网站vr用什么做
  • 适合高中生做网站的主题免费网页推广
  • 网站开发支付宝提现江西建设安全网站
  • 阿里巴巴外贸网站首页建设一个旅游平台网站需要多少资金
  • 做微信公众号页面的网站用自己的电脑做服务器建网站
  • 网站本科5000元网站seo推广
  • 卖房子上哪个网站最好卖做网站 多少人
  • 常熟智能网站开发呼和浩特建设厅官方网站
  • 做理财的网站好天元建设集团有限公司济南第六建筑工程分公司
  • 主流网站关键词排名服务推广软文范例
  • 做pc端网站基本流程网站备案注销找哪个部门