Http 获取JSON

package com.ls.utils;

import jakarta.servlet.http.HttpServletRequest;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

/*
这两个工具类用来些spring speimhmvc
请大家指点 git@github.com:Lartimes2004/mySpring

* @author Lartimes * @version 1.0 * @description: * @since 2023/10/24 22:04 */ public class HttpGetJson { private HttpGetJson() { } public static String getJson(HttpServletRequest request) { StringBuilder result = new StringBuilder(); BufferedReader in = null; try { in = new BufferedReader(new InputStreamReader( request.getInputStream(), StandardCharsets.UTF_8)); String line; while ((line = in.readLine()) != null) { result.append(line); } } catch (IOException e) { e.printStackTrace(); } finally { try { if (in != null) { in.close(); } } catch (IOException e) { e.printStackTrace(); } } return result.toString(); } }

 

posted @ 2023-12-05 23:12  lartimes  阅读(22)  评论(1)    收藏  举报