gpt4 book ai didi

kotlin - 如何在Ktor客户端中设置内容类型字符集(不是接受字符集)

转载 作者:行者123 更新时间:2023-12-02 12:51:45 29 4
gpt4 key购买 nike

这里的初学者
还有其他方法可以添加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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com