【发布时间】:2020-02-07 07:00:05
【问题描述】:
我正在查看 HTTP 请求采样器中的内容编码字段。不要将此与 HTTP Content-Type 标头混淆。
默认情况下,内容编码字段中的值为空。空是什么意思? jmeter HTTPRequest 的默认内容编码是什么?是 ASCII 还是 ANSI 还是 UTF-8?
这个guide只提到它不是必填字段。
【问题讨论】:
-
你希望用这个值做什么?我觉得没有效果
我正在查看 HTTP 请求采样器中的内容编码字段。不要将此与 HTTP Content-Type 标头混淆。
默认情况下,内容编码字段中的值为空。空是什么意思? jmeter HTTPRequest 的默认内容编码是什么?是 ASCII 还是 ANSI 还是 UTF-8?
这个guide只提到它不是必填字段。
【问题讨论】:
Dmitri's answer 指向与 查询字符串 编码相关的代码,但这导致我查看 PostWriter class 的代码,它创建了实际的 body请求 - 如果采样器不提供内容编码 - ISO-8859-1 用于对正文进行编码:
public static final String ENCODING = StandardCharsets.ISO_8859_1.name();
...
String contentEncoding = sampler.getContentEncoding();
if(contentEncoding == null || contentEncoding.length() == 0) {
contentEncoding = ENCODING;
}
【讨论】:
// Check if the sampler has a specified content encoding
if (JOrphanUtils.isBlank(lContentEncoding)) {
// We use the encoding which should be used according to the HTTP spec, which is UTF-8
lContentEncoding = EncoderCache.URL_ARGUMENT_ENCODING;
}
/** The encoding which should be usd for URLs, according to HTTP specification */
public static final String URL_ARGUMENT_ENCODING = StandardCharsets.UTF_8.name();
所以将该字段留空等于将其设置为UTF-8
【讨论】: