JMeter 4.0 HTTP RAW请求无正确响应,是否需添加JSESSIONID?
嗨,我来帮你捋清楚当前遇到的问题~
首先看你的采样器结果返回了401 Unauthorized,还有WWW-Authenticate: Basic realm="Realm",这说明服务端要求Basic身份验证,这才是你没得到预期success响应的核心原因,不过我还是针对你的Cookie问题和整体解决方案一步步说明:
关于是否需要手动在请求数据里添加Cookie: JSESSIONID?
完全不需要手动添加!你已经配置了HTTP Cookie管理器,它会自动捕获服务端返回的Set-Cookie(比如你采样器结果里的JSESSIONID=A1928A9F41209E241F4ABAFB6DC515E9),并在后续请求中自动带上这个Cookie。如果发现没自动带上,可以检查这两点:
- 确保HTTP Cookie管理器的作用域覆盖你的HTTP RAW请求(比如放在同一个线程组下,且位置在请求之前)
- 开启Cookie管理器的Debug模式:打开Cookie管理器的高级设置,勾选“Debug”,运行后就能在日志里看到Cookie的捕获和发送详情,方便排查问题
解决401未授权的关键步骤
你需要给请求添加Basic身份验证,具体操作如下:
- 右键你的线程组 → 「添加」→ 「配置元件」→ 「HTTP Authorization管理器」
- 在管理器中填入对应信息:
- 用户名:服务端要求的认证用户名
- 密码:对应的认证密码
- Realm:可以填采样器结果里的
Realm(就是Basic realm="Realm"中的内容) - 前缀:留空或者填写
Basic(大部分场景不需要手动填,JMeter会自动处理)
- 重新运行测试,查看结果树里的请求头,确认是否包含
Authorization: Basic xxxxxxx(xxxxx是用户名密码经过Base64编码后的字符串)
你提供的原始数据参考
采样器结果
Thread Name: Thread Group 1-1 Sample Start: 2018-05-15 18:30:14 IST Load time: 20014 Connect Time: 0 Latency: 10 Size in bytes: 2 Sent bytes:0 Headers size in bytes: 0 Body size in bytes: 2 Sample Count: 1 Error Count: 0 Data type ("text"|"bin"|""): text Response code: 401 Response message: Unauthorized Response headers: Server: Apache-Coyote/1.1 X-Content-Type-Options: nosniff X-XSS-Protection: 1; mode=block Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: 0 X-Frame-Options: DENY Set-Cookie: JSESSIONID=A1928A9F41209E241F4ABAFB6DC515E9; Path=/bbbp/; HttpOnly WWW-Authenticate: Basic realm="Realm" Content-Type: application/json;charset=UTF-8 Transfer-Encoding: chunked Date: Tue, 15 May 2018 12:54:07 GMT SampleResult fields: ContentType: DataEncoding: null
请求
POST /bbbp/api/uploadFiles HTTP/1.1 Host: devserver.sdrc.co.in Connection: keep-alive Content-Length: 25358 Accept: application/json, text/plain, */* Origin: http://devserver.sdrc.co.in:8080 X-Requested-With: XMLHttpRequest Content-Type: Type: application/json Referer: http://devserver.sdrc.co.in:8080/bbbp/data-entry-awareness User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36 Accept-Language: en-GB,en-US;q=0.9,en;q=0.8 Accept-Encoding: gzip, deflate
响应数据
a2
内容的提问来源于stack exchange,提问作者Krishna Sagar




