Example usage for java.net URLConnection getURL

List of usage examples for java.net URLConnection getURL

Introduction

In this page you can find the example usage for java.net URLConnection getURL.

Prototype

public URL getURL() 

Source Link

Document

Returns the value of this URLConnection 's URL field.

Usage

From source file:Main.java

public static void main(String args[]) throws Exception {

    URL u = new URL("http://www.java2s.com");
    URLConnection uc = u.openConnection();

    System.out.println(uc.getURL());
}

From source file:MainClass.java

public static void main(String args[]) {

    URL u;//from  w w w  . j a  v  a  2 s. c o  m
    URLConnection uc;

    try {
        u = new URL("http://www.java2s.com/");
        try {
            uc = u.openConnection();
            System.out.println(uc.getURL());
        } catch (IOException e) {
            System.err.println(e);
        }
    } catch (MalformedURLException e) {
        System.err.println(e);
    }

}

From source file:Urls.java

private static String getDefaultCharset(URLConnection connection) {
    URL url = connection.getURL();
    if (Urls.isLocalFile(url)) {
        String charset = System.getProperty("file.encoding");
        return charset == null ? "ISO-8859-1" : charset;
    } else {/*from w w w  .ja  v a  2  s.  c  o  m*/
        return "ISO-8859-1";
    }
}

From source file:com.meetingninja.csse.database.BaseDatabaseAdapter.java

protected static int sendPostPayload(URLConnection connection, String payload) throws IOException {
    Log.d(IRequest.POST, "[URL] " + connection.getURL().toString());
    logPrint(payload);//from   www . j  av a2  s.  c om

    DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
    wr.writeBytes(payload);
    wr.flush();
    wr.close();
    return ((HttpURLConnection) connection).getResponseCode();
}

From source file:org.kalypso.commons.java.net.UrlUtilities.java

/**
 * Find content encoding for the given connection. If the connection denotes a platform-url, we fetch the encoding
 * from the underlying resource, as the connection will not return a valid charset.
 *///w ww  .  j a va2s .  co  m
public static String findEncoding(final URLConnection connection) {
    final IFile file = ResourceUtilities.findFileFromURL(connection.getURL());
    if (file == null)
        return connection.getContentEncoding();

    try {
        return file.getCharset();
    } catch (final CoreException e) {
        e.printStackTrace();
        return connection.getContentEncoding();
    }
}

From source file:com.moviejukebox.themoviedb.tools.WebBrowser.java

private static String createCookieHeader(URLConnection cnx) {
    String host = cnx.getURL().getHost();
    StringBuilder cookiesHeader = new StringBuilder();
    for (Map.Entry<String, Map<String, String>> domainCookies : cookies.entrySet()) {
        if (host.endsWith(domainCookies.getKey())) {
            for (Map.Entry<String, String> cookie : domainCookies.getValue().entrySet()) {
                cookiesHeader.append(cookie.getKey());
                cookiesHeader.append("=");
                cookiesHeader.append(cookie.getValue());
                cookiesHeader.append(";");
            }//from   www .  ja  v  a 2 s .  com
        }
    }
    if (cookiesHeader.length() > 0) {
        // remove last ; char
        cookiesHeader.deleteCharAt(cookiesHeader.length() - 1);
    }
    return cookiesHeader.toString();
}

From source file:com.omertron.themoviedbapi.tools.WebBrowser.java

private static String createCookieHeader(URLConnection cnx) {
    String host = cnx.getURL().getHost();
    StringBuilder cookiesHeader = new StringBuilder();
    for (Map.Entry<String, Map<String, String>> domainCookies : COOKIES.entrySet()) {
        if (host.endsWith(domainCookies.getKey())) {
            for (Map.Entry<String, String> cookie : domainCookies.getValue().entrySet()) {
                cookiesHeader.append(cookie.getKey());
                cookiesHeader.append("=");
                cookiesHeader.append(cookie.getValue());
                cookiesHeader.append(";");
            }/*from  w  ww . j a v  a2 s  .co  m*/
        }
    }
    if (cookiesHeader.length() > 0) {
        // remove last ; char
        cookiesHeader.deleteCharAt(cookiesHeader.length() - 1);
    }
    return cookiesHeader.toString();
}

From source file:com.moviejukebox.tools.WebBrowser.java

/**
 * Check the URL to see if it's one of the special cases that needs to be worked around
 *
 * @param URL The URL to check/* w  w  w. j av a  2  s. c o m*/
 * @param cnx The connection that has been opened
 */
private static void checkRequest(URLConnection checkCnx) {
    String checkUrl = checkCnx.getURL().getHost().toLowerCase();

    // TODO: Move these workarounds into a property file so they can be overridden at runtime
    // A workaround for the need to use a referrer for thetvdb.com
    if (checkUrl.contains("thetvdb")) {
        checkCnx.setRequestProperty("Referer", "http://forums.thetvdb.com/");
    }

    // A workaround for the kinopoisk.ru site
    if (checkUrl.contains("kinopoisk")) {
        checkCnx.setRequestProperty("Accept", "text/html, text/plain");
        checkCnx.setRequestProperty("Accept-Language", "ru");
        checkCnx.setRequestProperty("User-Agent",
                "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6");
    }
}

From source file:com.omertron.thetvdbapi.tools.WebBrowser.java

/**
 * Create the cookies for the header//from ww  w . j a va  2 s  .c  o  m
 *
 * @param cnx
 */
private static String createCookieHeader(URLConnection cnx) {
    String host = cnx.getURL().getHost();
    StringBuilder cookiesHeader = new StringBuilder();
    for (Map.Entry<String, Map<String, String>> domainCookies : cookies.entrySet()) {
        if (host.endsWith(domainCookies.getKey())) {
            for (Map.Entry<String, String> cookie : domainCookies.getValue().entrySet()) {
                cookiesHeader.append(cookie.getKey());
                cookiesHeader.append("=");
                cookiesHeader.append(cookie.getValue());
                cookiesHeader.append(";");
            }
        }
    }
    if (cookiesHeader.length() > 0) {
        // remove last ; char
        cookiesHeader.deleteCharAt(cookiesHeader.length() - 1);
    }
    return cookiesHeader.toString();
}

From source file:com.buglabs.dragonfly.util.WSHelper.java

/**
 * Gets data from {@link URLConnection}//  ww  w  .  j a  va  2s .  com
 * 
 * @param conn
 * @param isBug
 *            specifies whether url refers to the BUG
 * @return
 * @throws IOException
 */
protected static String get(URLConnection conn, boolean isBug) throws IOException {
    return get(conn.getURL(), isBug);
}