import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class URLTesting
{
private static Map<String, List<String>> headerMap;
private static boolean key;
public static void main(String args[]) throws MalformedURLException, IOException
{
URL url=new URL("http://www.google.com:80/html/default.asp");
URLConnection urlcon=url.openConnection();
URL urltemp=new URL("http://www.google.com/html/default.asp");
HttpURLConnection httpurlcon=(HttpURLConnection) url.openConnection();
System.out.println("Protocol:"+url.getProtocol());
System.out.println("Port for URL:"+url.getPort());
System.out.println("Port for urltemp:"+urltemp.getPort());
System.out.println("Host:"+url.getHost());
System.out.println("File:"+url.getFile());
//System.out.println("String representation of URl:"+url.getExternalForm());
System.out.println("Content Type:"+urlcon.getContentType());
System.out.println("Content Encoding:"+urlcon.getContentEncoding());
System.out.println("Content Length:"+urlcon.getContentLength());
System.out.println("Date:"+ new Date(urlcon.getDate()));
System.out.println("Last Modified:"+new Date(urlcon.getLastModified()));
System.out.println("Expiration:"+new Date(urlcon.getExpiration()));
System.out.println("Request method:"+httpurlcon.getRequestMethod());
System.out.println("Responsee Message:"+httpurlcon.getResponseMessage());
System.out.println("Response code:"+httpurlcon.getResponseCode());
Map<String, List<String>>
HeaderMap=httpurlcon.getHeaderFields();
Set<String> headerKeys=(Set<String>) HeaderMap.keySet();
System.out.println("....NOW THW HEADER....");
for(String key:headerKeys)
{
System.out.println("Key:"+key);
System.out.println("value:"+HeaderMap.get(key));
System.out.println("--------------");
}
}
static class string {
public string() {
}
}
private static class set<T> {
public set() {
}
}
}
A blog provide anexample with sample code for swing , servlet, jdbc and odbc connection to database, jsp, servlets, taglib, sql server, cassandra and many more. we also provide Apache camel sample code for integration.
Saturday, October 13, 2012
URL connection send and properties
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment