我需要用 OkHttp 重现错误,这样我就可以提交错误或在 StackOverflow 上提问。
无需大量设置即可执行此操作的最简单方法是什么?
我读过 https://stackoverflow.com/help/how-to-ask和 https://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)
#!行意味着它也将像 shell 脚本一样运行
$ ./example.main.kts
OkHttp
======
See the [project website][okhttp] for documentation and APIs.
...
关于okhttp - 如何重现 OkHttp 的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66364993/