I am trying to send a POST request from my Angular client to a Spring endpoint. Here is the endpoint in my HomeController:
@RestController()
public class HomeController {
@PostMapping(value = "/payment/{unique_transaction_id}")
public ResponseEntity<WpfResponse> handleWpfMessage(@PathVariable("unique_transaction_id") String unique_transaction_id,
@RequestBody WpfPaymentsDTO transaction, HttpServletRequest request) throws Exception {
/// ....
MessageProcessor messageProcessor = processors.getOrDefault(transaction.getTransaction_type(), defaultProcessor);
return ResponseEntity.ok(messageProcessor.processMessage(merchant, contract, terminal.get(), transaction, request));
}
}
This is my TypeScript code snippet:
save(main: MainForm, hash: string): void {
const headers = new HttpHeaders();
headers.append('Accept', 'application/json');
headers.append('Content-Type', 'application/json');
this.http.post('http://localhost:8080/some_package/payment/ckjzqtyxh5pnavbjecujhuvzaa5q8n74', JSON.stringify(main), { headers }).subscribe();
}
However, when I run the code, I encounter the following error:
HttpErrorResponse {headers: HttpHeaders, status: 415, statusText: "Unsupported Media Type", url: "http://localhost:8080/some_package/payment/ckjzqtyxh5pnavbjecujhuvzaa5q8n74", ok: false, …}error: nullheaders: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}lazyInit: ƒ ()lazyUpdate: nullnormalizedNames: Map(0) {}__proto__: Objectmessage: "Http failure response for http://localhost:8080/some_package/payment/ckjzqtyxh5pnavbjecujhuvzaa5q8n74: 415 Unsupported Media Type"name: "HttpErrorResponse"ok: falsestatus: 415statusText: "Unsupported Media Type"url: "http://localhost:8080/some_package/payment/ckjzqtyxh5pnavbjecujhuvzaa5q8n74"__proto__: HttpResponseBase
Can anyone provide guidance on how to resolve this issue?
WpfPaymentsDTO:
public class WpfPaymentsDTO {
private String transaction_id;
private String transaction_type;
private String currency;
private Integer amount;
.....
}