本文介绍了JSP发出http获取请求并获取json响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想做一个获取 json 响应的 http get 请求.在那个会话响应中,我想将一个值存储到我的会话中.这是如何实现的?
I would like to make a http get request which gets a json response. In that session response I would like to store a value into my session. How is this achievable?
谢谢
推荐答案
这里是示例代码.您将在 recvbuff 中得到响应.
Here is the sample code. You'll have response in recvbuff.
<%@page import="java.io.*" %>
<%@page import="java.net.*" %>
<%
String recv;
String recvbuff;
URL jsonpage = new URL("http://www.yoursite.com/jsonresponse");
URLConnection urlcon = jsonpage.openConnection();
BufferedReader buffread = new BufferedReader(new InputStreamReader(urlcon.getInputStream()));
while ((recv = buffread.readLine()) != null)
recvbuff += recv;
buffread.close();
System.out.println(recvbuff);
%>
这篇关于JSP发出http获取请求并获取json响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!