I have a servlet where I need data from external url.
When am trying to simply request (GET) a website through a url I got the following exception:
java.net.ProtocolException: Server redirected too many times (20)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:583)
But, isn't there a redirect.
Try the code:
... change the url
URL url = new URL("http://10.254.69.28:8989/ctx1/crossctx.act");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setFollowRedirects(true);
con.setInstanceFollowRedirects(true);
con.connect();
InputStream in = con.getInputStream();
StringBuffer respo = new StringBuffer();
int chr;
int ii=0;
while ((chr=in.read())!=-1) {
respo.append((char) chr); ii++;
if (ii>100) break;
}
in.close();
System.out.println( respo.toString());
How to resolve the problem?