working web-based entent code

This commit is contained in:
Lincpay Tech
2025-12-03 00:38:19 +05:30
parent c2acccc535
commit 9634939982
5 changed files with 123 additions and 4 deletions
@@ -141,6 +141,46 @@ public class HttpService {
return response;
}
public HashMap<String, String> postFormRequest(String url, String formBody) {
HashMap<String, String> response = new HashMap<>();
try {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
log.info("🌐 Sending FORM POST to: {}", url);
log.info("📦 Payload: {}", formBody);
ResponseEntity<String> restResponse = restClient.post()
.uri(url)
.headers(h -> h.addAll(headers))
.body(formBody)
.retrieve()
.toEntity(String.class);
response.put("respCode", String.valueOf(restResponse.getStatusCode().value()));
// HTML RESPONSE directly stored
response.put("data", restResponse.getBody());
log.info("✅ FORM POST Response Status: {}", restResponse.getStatusCode());
} catch (HttpClientErrorException e) {
log.error("❌ FORM POST Error: {} - {}", e.getStatusCode(), e.getMessage());
response.put("respCode", String.valueOf(e.getStatusCode().value()));
response.put("data", e.getResponseBodyAsString()); // still HTML or error string
} catch (Exception e) {
log.error("❌ FORM POST Exception: {}", e.getMessage(), e);
response.put("respCode", "500");
response.put("data", "HttpService FORM Error: " + e.getMessage());
}
return response;
}