postman请求结果乱码,由图可见,返回的结果都是?????
请求背景:get方法测试的接口是mock提供的接口中转经过bff项目,使用HttpUtil中封装的方法
/** * 发送GET请求 * */ public static Object sendGet(String strUrl,String path){ String url = HttpUtil.CheckRequest(path); Object strReturn=""; HttpGet httpGet = new HttpGet(url + strUrl); CloseableHttpClient httpclient = null; CloseableHttpResponse response1=null; try { httpclient = HttpClients.createDefault(); response1 = httpclient.execute(httpGet); HttpEntity entity1 = response1.getEntity(); strReturn= EntityUtils.toString(entity1) ; EntityUtils.consume(entity1); }catch(Exception e){ e.printStackTrace(); }finally { try { if(response1!=null){ response1.close(); } } catch (IOException e) { e.printStackTrace(); } } return strReturn; }
解决办法:非常简单,在路径这里添加转码