美文网首页
Okhttp header 中文异常解决方案

Okhttp header 中文异常解决方案

作者: Leo_o | 来源:发表于2022-03-23 17:39 被阅读0次
    private fun getValidUA(userAgent: String?): String {
            if (userAgent.isNullOrEmpty()) return ""
            val sb = StringBuilder()
            var i = 0
            val length = userAgent.length
            while (i < length) {
                val c = userAgent[i]
                if (c <= '\u001f' || c >= '\u007f') {//检测为不合法字符,就转为unicode 编码
                    sb.append(String.format("\\u%04x", c.code))
                } else {
                    sb.append(c)
                }
                i++
            }
            return sb.toString()
        }
    

    相关文章

      网友评论

          本文标题:Okhttp header 中文异常解决方案

          本文链接:https://www.haomeiwen.com/subject/lfxhjrtx.html