From 3dc8f16de0364823416633b516bb35e0ff58b3a7 Mon Sep 17 00:00:00 2001 From: Felipe Cotti Date: Sun, 27 Oct 2024 17:01:32 -0300 Subject: [PATCH] Turns out captchas can be larger than 1KB. And turns out people use websites from inside Instagram. --- .../DTOs/Messages/InsertMessage.cs | 2 +- src/input-example/example.html | 29 ++++++++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/Guestbooky/Guestbooky.API/DTOs/Messages/InsertMessage.cs b/src/Guestbooky/Guestbooky.API/DTOs/Messages/InsertMessage.cs index f116579..7a83f3e 100644 --- a/src/Guestbooky/Guestbooky.API/DTOs/Messages/InsertMessage.cs +++ b/src/Guestbooky/Guestbooky.API/DTOs/Messages/InsertMessage.cs @@ -17,6 +17,6 @@ public record InsertMessageRequestDto [JsonPropertyName("captchaResponse")] [Required(ErrorMessage = "The captcha challenge response is required")] - [StringLength(1024)] + [StringLength(2048)] public string CaptchaResponse { get; init; } } \ No newline at end of file diff --git a/src/input-example/example.html b/src/input-example/example.html index 0f62e4d..81b219d 100644 --- a/src/input-example/example.html +++ b/src/input-example/example.html @@ -133,22 +133,23 @@ document captchaResponse, }; - const response = await fetch(this.action, { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(data), - }); + const dataJson = JSON.stringify(data); - if (response.status >= 200 && response.status <= 299) { - alert("Note added successfully!"); - this.reset(); // Clear the form fields - } else { - const problem = await response.json(); - alert(problem); + const xhr = new XMLHttpRequest(); + xhr.open("POST", this.action, true); + xhr.setRequestHeader("Content-Type", "application/json"); + xhr.setRequestHeader('Content-Length', dataJson.length); + xhr.send(dataJson); + + xhr.onload = function () { + if (xhr.status >= 200 && xhr.status <= 299) { + alert("Message sent successfully."); + this.reset(); // Clear the form fields + } else { + alert("An error " + xhr.status + "occurred: " + xhr.responseText); + } } - }); +});