Turnstile Server-side validation API always returns bad-request

Hello, I try to implement server side validation in .net core but I always get response like this:
“{"success":false,"error-codes":["bad-request"]}”

I tried both this:
HttpClient httpClient = new HttpClient();
MultipartFormDataContent form = new MultipartFormDataContent();
form.Add(new StringContent(“1x0000000000000000000000000000000AA”), “secret”);
form.Add(new StringContent(Request.Form[“cf-turnstile-response”].FirstOrDefault()), “response”);
HttpResponseMessage response = await httpClient.PostAsync(“apiUrl”, form);
response.EnsureSuccessStatusCode();
httpClient.Dispose();
string sd = response.Content.ReadAsStringAsync().Result;

and this:
object test = new
{
secret = “1x0000000000000000000000000000000AA”,
response = Request.Form[“cf-turnstile-response”].FirstOrDefault()
};
var cloudflareTurnstileResult = await new HttpClient().PostAsync(“apiUrl”, new StringContent(JsonConvert.SerializeObject(test), Encoding.UTF8, “application/json”));
var cloudflareTurnstileSuccess = ((JObject)JsonConvert.DeserializeObject(cloudflareTurnstileResult.Content.ReadAsStringAsync().Result))[“success”].Value();

How else can I call this api or what am I doing wrong?

  1. You need to submit the remote ip address like described here: https://developers.cloudflare.com/turnstile/get-started/server-side-validation/
  2. Content-type should be “application/x-www-form-urlencoded; charset=utf-8” and not “application/json” :slight_smile: