Code example for URLConnection

Methods: addRequestProperty

0
    /* create a socket */ 
    private URLConnection createConnection(String searchurl, StringBuffer referrer) throws IOException, MalformedURLException {
 
        URL sendurl = new URL(searchurl);
        URLConnection connection = sendurl.openConnection();
        connection.addRequestProperty("Referer", referrer.toString());
        return connection;
    } 
 
    /*initialize search url*/ 
    private String getSearchUrl(int start, String searchstring) {
 
        String startparam = "&start=" + start;
        String searchparam = "&q=" + searchstring;
        String googleapipath = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0";
 
        String url = googleapipath + startparam + searchparam;
        return (url);
    } 
 
    /* wrap stream to stringbuilder */