You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows Server 2019下Selenium Server编码兼容配置求助

问题解决:Windows Server上Selenium Server兼容多种Content-Type编码的方法

问题现象

  • 在Windows Server 2019上执行命令 java -jar selenium-server-4.9.0.jar standalone 启动Selenium独立服务后,使用Python发送请求时,仅当请求头设置为 {'Content-Type': 'application/json; charset=utf-8'} 才能正常创建会话;仅设置 {'Content-Type': 'application/json'} 时请求失败。
  • 但通过Docker运行 docker run -d -p 4444:4444 --name selenium selenium/standalone-chrome 时,无论是否在请求头中指定编码,甚至使用ASCII编码都能正常工作。

环境信息

  • Windows Server 2019
  • Google Chrome Version 112.0.5615.138
  • Selenium Server 4.9.0
  • ChromeDriver 112.0.5615.49

解决方法

1. 启动Selenium Server时指定Java默认编码为UTF-8

Windows环境下Java默认字符编码与Docker中的Linux环境存在差异,导致Selenium Server对Content-Type的校验更严格。启动时添加-Dfile.encoding=UTF-8参数强制统一编码:

java -Dfile.encoding=UTF-8 -jar selenium-server-4.9.0.jar standalone

2. 升级Selenium Server到最新稳定版

Selenium 4.9.0属于较早版本,后续版本可能修复了Windows环境下的编码兼容性问题。下载并使用最新的Selenium Server稳定版重新启动服务,测试请求兼容性。

3. 通过配置文件调整HTTP服务器编码规则

创建selenium-config.toml配置文件,添加HTTP编码相关配置:

[server]
port = 4444
[server.http]
charset = "UTF-8"

启动服务时指定该配置文件:

java -jar selenium-server-4.9.0.jar standalone --config selenium-config.toml

内容的提问来源于stack exchange,提问作者aminmr1375

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 17:57:52