mirror of
https://github.com/tursom/TursomServer.git
synced 2025-01-04 09:20:50 +08:00
fox http request bugs
This commit is contained in:
parent
4a4ceb3dd3
commit
4464bee33b
@ -1,10 +1,13 @@
|
||||
package cn.tursom.core
|
||||
|
||||
import java.io.*
|
||||
import java.io.File
|
||||
import java.io.InputStreamReader
|
||||
import java.io.OutputStream
|
||||
import java.net.HttpURLConnection
|
||||
import java.net.URL
|
||||
import java.net.URLEncoder
|
||||
import java.nio.charset.Charset
|
||||
import java.util.zip.GZIPInputStream
|
||||
|
||||
/**
|
||||
* 向指定URL发送GET方法的请求
|
||||
@ -44,7 +47,13 @@ fun sendGet(
|
||||
// println(key + "--->" + map[key])
|
||||
// }
|
||||
// 定义 BufferedReader输入流来读取URL的响应
|
||||
return InputStreamReader(connection.getInputStream(), Charset.defaultCharset()).readText()
|
||||
return connection.getInputStream().let {
|
||||
if (connection.contentEncoding?.contains("gzip") == true) {
|
||||
GZIPInputStream(it)
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}.readBytes().toUTF8String()
|
||||
}
|
||||
|
||||
fun sendGet(
|
||||
@ -196,7 +205,7 @@ fun sendPost(
|
||||
}
|
||||
|
||||
// 定义BufferedReader输入流来读取URL的响应
|
||||
return InputStreamReader(conn.getInputStream(), Charset.defaultCharset()).readText()
|
||||
return conn.getInputStream().readBytes().toUTF8String()
|
||||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
|
Loading…
Reference in New Issue
Block a user