java - HttpClient follow redirect -
i working on little project. aim of project log in website , get/handle information on site. moreover, open links , search through them well.
the server side looks this:
you need login php site. when sucessfully login session , redirected foo.username.bar.php (changed).
with code:
bufferedreader in = null; string data = null; try { list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(2); namevaluepairs.add(new basicnamevaluepair("username", user)); namevaluepairs.add(new basicnamevaluepair("passwort", pass)); httpclient client = new defaulthttpclient(); httppost request = new httppost(website); request.setentity(new urlencodedformentity(namevaluepairs)); httpresponse response = client.execute(request); in = new bufferedreader(new inputstreamreader(response.getentity() .getcontent())); stringbuffer sb = new stringbuffer(""); string l = ""; string nl = system.getproperty("line.separator"); while ((l = in.readline()) != null) { sb.append(l + nl); } in.close(); data = sb.tostring(); return data; } { if (in == null) { try { in.close(); return "error"; } catch (exception e) { e.printstacktrace(); } } } }
i sucessfully logged website. however, can see page source of php user confirmation site tells me sucessfully logged in , redirected.
now want see page source redirected , keep connection in order open more links on page.
do guys have idea how can solve this?
you need follow redirect (status 302) returned response. check out this answer.
Comments
Post a Comment