Package java.net

Examples of java.net.HttpURLConnection.connect()


        httpService.registerServlet( "/test", servlet, null, null );

        //Test that no cookies are currently set.
        HttpURLConnection client = getConnection( DEFAULT_BASE_URL + "/test", "GET" );

        client.connect();
        assertTrue( client.getResponseCode() == 200 );

    }

View Full Code Here


      // Specify what portion of file to download.
      connection.setRequestProperty("Range", "bytes=" + this.downloaded
          + "-");

      // Connect to server.
      connection.connect();

      // Make sure response code is in the 200 range.
      if ((connection.getResponseCode() / 100) != 2) {
        this.error();
      }
View Full Code Here

                    OutputStream o = conn.getOutputStream();
                    o.write(body);
                    o.flush();
                    o.close();
                }
                conn.connect();

                int responseCode = conn.getResponseCode();
                if (responseCode == 200) {
                    return true;
                }
View Full Code Here

            debugLog("Registering " + this.label + " at " + this.serverAddress);
        } else {
            conn = openServerConnection(this.nextReq);
            debugLog("Polling " + this.nextReq);
        }
        conn.connect();

        int pollResponseCode = conn.getResponseCode();
        if (pollResponseCode < 200 || pollResponseCode >= 300) {
            throw new IOException("Unexpected response code: "
                    + pollResponseCode);
View Full Code Here

                resp.writeOn(o);
            }
            o.flush();
            o.close();

            conn.connect();
            int replyResponseCode = conn.getResponseCode();
            if (replyResponseCode < 200 || replyResponseCode >= 300) {
                complain("Posting replies failed with code "
                        + replyResponseCode + " and message \""
                        + conn.getResponseMessage() + "\"");
View Full Code Here

        int connectionTimeout = config.getConnectionTimeout();
        conn.setConnectTimeout(connectionTimeout);
        if (conn instanceof HttpURLConnection && config.isFollowRedirects()) {
            // follow redirects to HTTPS
            HttpURLConnection con = (HttpURLConnection) conn;
            con.connect();
            int responseCode = con.getResponseCode();
            // redirect
            if (responseCode == HttpURLConnection.HTTP_MOVED_TEMP
                    || responseCode == HttpURLConnection.HTTP_MOVED_PERM
                    || responseCode == HttpURLConnection.HTTP_SEE_OTHER) {
View Full Code Here

    private int getResponseCode(String theme) {
        try {
            URL url = new URL(String.format("%s/VAADIN/themes/%s/favicon.ico", getBaseURL(), theme));
            HttpURLConnection connection = (HttpURLConnection)url.openConnection();
            connection.setRequestMethod("GET");
            connection.connect();

            return connection.getResponseCode();

        } catch (Exception e) {
            fail(e.getMessage());
View Full Code Here

                }
                httpsConnection.connect();
                httpConnection = httpsConnection;
            } else {
                httpConnection = (HttpURLConnection) url.openConnection();
                httpConnection.connect();
            }

            int responseCode = httpConnection.getResponseCode();
            if (responseCode != HttpURLConnection.HTTP_OK) {
                String responseMessage = httpConnection.getResponseMessage();
View Full Code Here

         try
         {
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            if (cookie != null)
               conn.addRequestProperty("Cookie", cookie);
            conn.connect();

            int rc = conn.getResponseCode();

            if (cookie == null)
            {
View Full Code Here

    private static void getResponse(String requestMethod, String path, UrlResponse response)
            throws MalformedURLException, IOException, ProtocolException {
        URL url = new URL("http://localhost:" + PORT + path);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod(requestMethod);
        connection.connect();
        String res = IOUtils.toString(connection.getInputStream());
        response.body = res;
        response.status = connection.getResponseCode();
        response.headers = connection.getHeaderFields();
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.