JMeter调用API已传入所有必填字段仍返回400响应码求助
Hey there, let's figure out why you're hitting that 400 Bad Request when calling the Snapmed contact API at https://snapmed.no/kontakt-1. A 400 error usually means the server can't make sense of your request, so here are the most likely issues and how to fix them:
Missing mandatory form fields
Contact forms almost always require more than just a CSRF token and redirect URL. Chances are you're skipping required fields likename,email,message, or a phone number that the server expects. Head over to the actual Snapmed contact page, right-click and inspect the form to list every<input>with anameattribute—all of these need to be included in your request body.CSRF token validation failure
Even though you're sendingcraft_csrf_token, make sure:- You grabbed the token correctly from the site's cookies or the form's hidden input (stale or incorrect tokens will get rejected by Craft CMS).
- The parameter name matches exactly what the server expects—double-check if it's really
craft_csrf_token(some setups use_csrfinstead).
Wrong request method
Confirm you're using the POST method for this endpoint. Contact forms never accept GET requests, so if you're accidentally using GET, that's a sure way to get a 400.Incorrect request headers
Servers often check headers likeContent-Typeto ensure your request body is formatted right. If you're sending form data, setContent-Type: application/x-www-form-urlencoded(for key-value pairs) ormultipart/form-data(if there are file uploads). If you're using JSON, make sure the header isapplication/jsonand your body is valid JSON.Invalid redirect parameter
Theredirectvalue needs to be a URL the server recognizes (either relative to the site or a valid absolute URL). If you're using an invalid or unauthorized URL here, the server might reject the request. Try using the same redirect value that the original form uses (check the form's hidden inputs or action attribute).
- Inspect the live form
Visit the Snapmed contact page, right-click > Inspect Element, then look at the<form>tag and all its child inputs. Note everynameattribute—these are the exact parameters you need to send. - Capture a working request
Use your browser's DevTools (Network tab) to submit the form manually. Copy the headers, form data, and CSRF token from that successful request to replicate it in your code. - Double-check your request body
Make sure all required fields are present, values are in the correct format (like a valid email address), and there are no typos in parameter names.
内容的提问来源于stack exchange,提问作者pragneshReddy Nandyala

