使用postman請求格式為body--raw-的相關調試


 

1.SSM框架的,如下示例解析

1     @ResponseBody
2     @RequestMapping(value = "/PostInfo")
3     public void enter(@RequestBody Map map) throws Exception {
4         JSONObject jsonToMap = JSONObject.fromObject(map); // map轉json
5         System.out.println("Enter--請求轉json:" + jsonToMap);
6         KeTuoRe kt = (KeTuoRe) JSONObject.toBean(decode, KeTuoRe.class);// 轉Bean
7         // ...拿到轉化數據進行業務處理
8     }

body--raw,參數傳輸使用json字符串。我的請求用的是加密數據,示例代碼里刪去了解碼這部分。測試可以用自己的json字符串整合業務。

 

2.springboot框架下,如下示例

@PostMapping(value = “/test”)
public JSONObject Test(InputStream inputStream) {
    JSONObject json=new JSONObject();
    String result = “”;
    try {
        ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
            int len;
            while ((len = inputStream.read(buffer)) != -1) {
                outSteam.write(buffer, 0, len);
            }
            outSteam.close();
            inputStream.close();
            result = new String(outSteam.toByteArray(), "UTF-8");//得到數據
            result = org.apache.commons.lang3.StringEscapeUtils.unescapeJava(result);//去轉義符 斜杠
            //String newStr = result.substring(1, result.length()-1);//去除頭和尾引號
        } catch (Exception e) {
            e.printStackTrace();
        }
    json.put(“result”, result);
    return json;
}

postman請求格式如上,請求的json字符串內容可以自己拼接一下。后台拿到數據后可加上自己業務就行。 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM