request to parse the json parameters and values ​​in the body

 public R proxy(HttpServletRequest request) {
        if (!request.getContentType().toLowerCase().equals(CONTENTTYPE)) {
            return R.error (101, "Please use application / json parameter");
        }
        Map requestMap = new HashMap<>();
        try {
            BufferedReader bufferedReader = new BufferedReader(new                                   
            InputStreamReader(request.getInputStream()));
            String bodyStr = IOUtils.read(bufferedReader);
            Gson gson = new Gson();
            requestMap = gson.fromJson(bodyStr, requestMap.getClass());
            log.info("requestMap:{}", requestMap.toString());
        } catch (Exception e) {
                         log.error ("Failed to parse request body parameters: {}", e.getMessage ());
                         return R.error (101, "Failed to parse request parameter");
        }
}

The dubbo package of alibaba needs to be introduced

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>dubbo</artifactId>
    <version>2.6.4</version>
</dependency>

Intelligent Recommendation

Parse the parameters except the request

The URL of the request is...

Parameters Request in Body HTTPUTIL

Direct code:  ...  ...

Use restTemplate to send a post request, the incoming parameters are in the requestBody request body, transmitted in json form

@PostMapping public ResponseResult add(User user){ HttpHeaders httpHeaders = new HttpHeaders(); MediaType type=MediaType.parseMediaType(“application/json;charset=UTF-8”); httpHeaders.setCo...

golang: Parse HTTP request parameters

The case in the design of "GO Programming Language" is only collected as notes. In this case, the HTTP request parameters are parsed into corresponding anonymous structures, and reflection i...

More Recommendation

FastApi --- Request Body - Multiple Parameters

content 1, mix using Path, Query and request body parameters 2, multiple request body parameters 3, a single value in the request body 4, multiple request body parameters and query parameters 5, embed...

REQUEST BODY JSON Format Management

In the top three classes, we learned about Groovy content. This course will lead you to learn how to manage interface tests. Request Body in an interface in a project lifecycle may make multiple chang...

Get JSON data in Request Body

code show as below:...

Okhttp common parameter set to json object into common configuration parameters request @Body

When a network request is based on a URL, all of the interfaces are the same address, and the request data is different interfaces configured through command field, and then all the parameters are req...

Adding JSON parameters from the front-end JS to the Body of the AXIOS GET request, depth resolution

in conclusion Let's talk about the conclusion:In the browser environment, the GET request based on XHR communication is unable to be introduced in Body.。 Note: To reach the more absolute conclusions, ...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top