Hi!
I'm trying to get the source of a website, and I'm doing that successfully.
The only thing is i need to be able to set the user-agent header in the request to the site.
This is my current code (slightly modified) to get the source from the page.
URL url = new URL("http://www.mycustomsite.com/page.html");
inputStream = new BufferedInputStream(url.openStream());
DataInputStream in = new DataInputStream(inputStream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line = new String();
String file = new String();
try {
while((line = br.readLine()) != null){
file += line+ "\n";
}
}catch(Throwable e){
System.out.println("Could not read line");
}
Writer output = new BufferedWriter(new FileWriter("C:/my_web_page.html"));
output.write(file);
What do i have to do to tell Java to add the user-agent header into request?
(It doesn't matter to me if i have to rewrite the whole thing, i just wanna know how)
Thanks!