JSP make http get request and get json response
17,657
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);
%>
Related videos on Youtube
Author by
user1375026
Updated on September 16, 2022Comments
-
user1375026 over 1 year
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?
Thanks
-
Alexandre Lavoie over 11 yearsSimply use the button "{}" it will indent all the selected zone and will appear as code.
-
Vahid Farahmand over 11 yearsdid that, but as it contains <% tags, (I think) my code disappeared in previw. Maybe I was doing something wrong...
-
user1375026 over 11 yearsAnd what is dest here? Is it meant to be jsonpage? Thanks for the help
-
Shreyas almost 8 yearsShouldn't the
URLConnection
part and theBufferedReader
part be surrounded in the try-catch block ?