JMeter进行API性能测试时遭遇Response code 400错误求助
Let's dig into this 400 error you're hitting during your performance testing. First, here's the key context from your sample result to ground our debugging:
Thread Name:SupplierAPI 1-1
Sample Start:2020-07-30 11:01:04 BST
加载时间:571 | 连接时间:429 | 延迟:571
字节大小:518 | 发送字节数:241 | 头部字节大小:179 | 正文字节大小:339
采样数:1 | 错误数:1
数据类型:text | 响应码:400 | 响应消息:Bad Request
HTTPSampleResult字段: ContentType: text/html; charset=us-ascii | DataEncoding: us-ascii
A 400 Bad Request almost always means the server is rejecting your request because it's malformed in some way. Here are the most common fixes to check:
Validate your request payload/parameters
Compare the request you're sending from JMeter to a working request (e.g., from Postman or curl). Look for missing required fields, JSON syntax errors (if you're sending JSON), or mismatched data types. Your sent byte count is 241—does that line up with the size of a known-good request? Even a missing comma in JSON or a misspelled parameter name can trigger a 400.Check your request headers
The response showsContentType: text/html, but if your SupplierAPI expects something likeapplication/jsonorapplication/x-www-form-urlencoded, this is a red flag. Make sure your JMeter HTTP Header Manager includes the correctContent-Typeheader, along with any other required headers (likeAuthorizationorAccept) that a successful request uses.Verify request encoding
TheDataEncodingis set tous-ascii—if your request includes non-ASCII characters (like special symbols or international text), this encoding might mangle the data. Try switching toUTF-8in JMeter's request settings and see if that resolves the issue. Also confirm the server supports the encoding you're using.Read the full response body
You mentioned the response body is 339 bytes—this almost certainly contains specific error details (e.g., "Missing required field: supplier_id" or "Invalid JSON syntax"). Open the "Response Data" tab in JMeter's View Results Tree listener to get this info; it'll point you straight to the problem instead of guessing.Double-check the request URL
Typos in the URL path, unencoded special characters in query parameters, or incorrect path variables can all cause a 400. For example, if your URL has a space that isn't replaced with%20, the server won't parse it correctly.
Start with checking the response body first—it's usually the fastest way to pinpoint the exact issue. Once you fix the malformed part of the request, that 400 should disappear.
内容的提问来源于stack exchange,提问作者Justin Lambert

