Using Post no Body Error: socket hang up [How to Solve]

Project scenario:

Due to environmental problems, the server is only allowed to use the post and get methods to call the interface. The delete interface written using the post method can be called locally, but an error is reported in the server.


Problem description

Use the post method for logical deletion and error reporting, and use @pathvariable to obtain the front-end transmission parameters:

@PostMapping("/delete/{userGroupIds}")
public ResponseBean<Object> deleteUserGroup(@PathVariable("userGroupIds") String userGroupIds){
    return userGroupService.deleteUserGroup(userGroupIds);
}

When using postman to call the server interface, the following error messages appear:

The front-end page calls the interface and reports the following error, cross domain:


Cause analysis:

The post method needs to use @Rquestbody to obtain parameters. This problem occurs when null is passed. The specific details were not clarified.


Solution:

Change the @pathvariable method to @rquestbody .

@PostMapping("/delete")
public ResponseBean<Object> deleteUserGroup(@RequestBody UserGroupIdDTO userGroupIds){
    return userGroupService.deleteUserGroup(userGroupIds);
}

The parameters in UserGroupIdDTO are as follows:

@Data
public class UserGroupIdDTO {
    private String userGroupId;
}

Read More: