String winningNumber = "";//同步的http请求
try {
URI uri = new URI(BjBiyingConstant.GET_WINNINGNUMBER_URL + "?gameEn=" + gameEn);
SimpleClientHttpRequestFactory schr = new SimpleClientHttpRequestFactory();
ClientHttpRequest chr = schr.createRequest(uri, HttpMethod.POST);
ClientHttpResponse res = chr.execute();
InputStream is = res.getBody(); //获得返回数据,注意这里是个流
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String str = "";
while ((str = br.readLine()) != null) {
// 解析JSON获取STR
System.out.println(str);
JSONObject jsonParam = JSON.parseObject(str);
Map<String, Object> resultMap = (Map<String, Object>) jsonParam;
winningNumber = (String) resultMap.get("resp");
System.out.println(winningNumber);
}
} catch (URISyntaxException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return winningNumber;
Java httpClient 请求 可以在SpringMvc中使用
最新推荐文章于 2022-07-27 16:36:18 发布