``科特林
导入 okhttp3.OkHttpClient
导入 okhttp3.Request
导入 okhttp3.Response
有趣的主(){
val proxyHost = "www.duoip.cn"
val 端口 = 8000
val url = "https://www.10jqka.com.cn/"
val proxy = Proxy(Proxy.Type.HTTP, InetSocketAddress(proxyHost, proxyPort))
val client = OkHttpClient.Builder().proxy(proxy).build()
val 请求 = Request.Builder()
.url(网址)
。建造()
val 响应 = client.newCall(request).execute()
if (!response.isSuccessful) {
throw IOException("意外代码 ${response}}
````
标签:cn,val,代码,爬虫,okhttp3,抓取,导入,proxy,OkHttpClient From: https://blog.51cto.com/u_16348242/8346895