I would like to pass String type strings in a different way than query parameters for server-client communication in Rest API.The sources we tried are as follows:
Client Side
HttpHeaders heads = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_PLAIN_TEXT);
String sendparam = "test";
HttpEntity <String > request = new HttpEntity <String, > (sendparm, headers);
restTemplate.postForObject(url, request, String.class);
Server Side
@RequestMapping(value="/test",consumes=MediaType.APPLICATION_PLAIN_TEXT,METHOD="POST")
public void testPost(@ResponseBodyHttpEntity<String>request){
String receiveParam=request.getBody;
}
I wanted to pass the contents of the sendparam to the receiveparam on the server side, but it didn't work well.
I would appreciate it if you could let me know which URL you would like to refer to.
@RequestBody is an annotation that declares the type of body.
In other words, you don't need to declare HttpEntity, please declare String directly.
@PostMapping(value="/api/v1/snippet")
publicResponseEntity<?>create(@RequestBodyStringtext){
System.out.println(String.format("Received text is %s., text));
return ResponseEntity.ok().build();
}
I'm sorry I'm not good at Japanese because I'm Malaysian.
584 PHP ssh2_scp_send fails to send files as intended
920 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
578 Understanding How to Configure Google API Key
576 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2024 OneMinuteCode. All rights reserved.