import java.net.*;
import java.io.*;
public class HTTP {
private String baseURL;
private String path;
private String fullPath;
private HttpURLConnection http;
public HTTP(String url){
this.fullPath=url.indexOf("http://")==0?url:"http://".concat(url);
this.baseURL=getBaseUrl(url);
this.path="";
this.openConnection();
}
public void addHeaders(String[] headers,String values){
for(int i=0;i<headers.length;i++);
}
public void changePath(String path){
this.path=path;
this.fullPath=this.baseURL.concat(path);
this.openConnection();
}
public static String getBaseUrl(String url){
String val="http://";
if(!url.contains("http://")) url="http://".concat(url);
String results[]=url.split("/");
if(results.length>=3) return val.concat(results[2]);
return "";
}
private void openConnection(){
try {
URL u = new URL(this.fullPath);
this.http = (HttpURLConnection) u.openConnection();
}catch (MalformedURLException ex) {
System.err.println(this.fullPath + " is not a URL I understand");
}catch (IOException ex) {
System.err.println(ex);
}
}
public void setHeader(String header,String value){
this.http.setRequestProperty(header, value);
}
public void addHeader(String header,String value){
this.http.addRequestProperty(header, value);
}
public void printHeaders(){
for (int j = 1; ; j++) {
String header = this.http.getHeaderField(j);
String key = this.http.getHeaderFieldKey(j);
if (header == null || key == null) break;
System.out.println(this.http.getHeaderFieldKey(j) + ": " + header);
}
}
public static void main(String[] args) {
HTTP h=new HTTP("http://google.com/agsa");
h.setHeader("Referer", "wwwa.ga.a");
h.printHeaders();
}
}