作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这里的初学者
还有其他方法可以添加Content-Type Charset而不是header("Content-Type", "application/json; charset=UTF-8")
吗?
val client = HttpClient {
Charsets {
Charsets.UTF_8
} // This sets the accept header only, does not set the content type charset
}
client.put<HttpResponse> {
contentType(ContentType.Application.Json)
url(url)
body =body
}
client.put<HttpResponse> {
header("Content-Type", "application/json; charset=UTF-8")
contentType(ContentType.Application.Json)
url(url)
body = body
}
最佳答案
要使用Ktor API指定 header ,您必须为其指定一个参数:
client.put<HttpResponse> {
contentType(ContentType.Application.Json.withParameter("charset", "utf-8"))
url(url)
body = body
}
关于kotlin - 如何在Ktor客户端中设置内容类型字符集(不是接受字符集),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60338534/
我是一名优秀的程序员,十分优秀!