java - How do I send a cookie while trying to grab a sites source? -
i trying grab site's source code using code private static string geturlsource(string url) throws ioexception { url url = new url(url); urlconnection urlconn = url.openconnection(); bufferedreader in = new bufferedreader(new inputstreamreader( urlconn.getinputstream(), "utf-8")); string inputline; stringbuilder = new stringbuilder(); while ((inputline = in.readline()) != null) a.append(inputline); in.close(); return a.tostring(); } when grab site code way error needing allow cookies. there anyway allow cookies in java application can grab source code? have cookie browser uses log me in if helps. thanks john this way have deal raw request data, go apache http client gives abstraction , methods allow set headers in request