okhttp - 如何重现 OkHttp 的错误

标签 okhttp

我需要用 OkHttp 重现错误,这样我就可以提交错误或在 StackOverflow 上提问。

无需大量设置即可执行此操作的最简单方法是什么?

我读过 https://stackoverflow.com/help/how-to-askhttps://stackoverflow.com/help/minimal-reproducible-example但我还是卡住了?帮帮我!

最佳答案

在 Intellij 中制作一个 Kotlin 脚本,将它放在任何源文件夹之外,并确保它以 .main.kts 文件名结尾。

例子.main.kts

#!/usr/bin/env kotlin

@file:Repository("https://repo1.maven.org/maven2/")
@file:DependsOn("com.squareup.okhttp3:okhttp:4.9.0")
@file:CompilerOptions("-jvm-target", "1.8")

import okhttp3.OkHttpClient
import okhttp3.Request

val client = OkHttpClient()

val request = Request.Builder()
  .url("https://raw.github.com/square/okhttp/master/README.md")
  .build()

val body = client.newCall(request).execute().use {
  it.body!!.string()
}

println(body)

enter image description here

#!行意味着它也将像 shell 脚本一样运行

$ ./example.main.kts          
OkHttp
======

See the [project website][okhttp] for documentation and APIs.
...

关于okhttp - 如何重现 OkHttp 的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66364993/

相关文章:

android - OkHttp3库的RequestBody和MultipartBody的区别?

java - 如何使用 OkHttp - Android 将 html 源代码获取到字符串

gzip - 改造: how to parse GZIP'd response without Content-Encoding: gzip header

android - Okhttp post json 数组

spring-boot - 将客户端证书与改造 (okhttp) 一起使用时出现 bad_certificate 错误,但与 curl 一起使用时效果很好

android - 如何获取OkHttp 4.x的UserAgent?

android - 为什么认证被绕过

java - 得到 'IOException: hostname was not verified' ,尽管给定的主机名(IP 地址)与通用名称匹配

android - 如何将来自 Okhttp 的响应转换为输入流

okhttp - MockWebServer:java.lang.NoSuchMethodError