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?
我想创建一个获取json响应的http get请求。在该会话响应中,我想将值存储到我的会话中。这怎么可以实现?
Thanks
1 个解决方案
#1
7
Here is the sample code. You'll have response in recvbuff.
这是示例代码。你会在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);
%>
#1
7
Here is the sample code. You'll have response in recvbuff.
这是示例代码。你会在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);
%>