Package java.net

Examples of java.net.HttpURLConnection.addRequestProperty()


        HttpURLConnection client = getConnection( DEFAULT_BASE_URL + "/test", "GET" );

        int parameterCount = 16;
        for ( int i = 0; i < parameterCount; ++i )
        {
            client.addRequestProperty( "k" + i, "v" + i );
        }
        client.connect();
        assertTrue( client.getResponseCode() == 200 );
        Map rp = new HashMap();
       
View Full Code Here


       
        String endpointAddress =
            "http://localhost:9080/webapp/bookstore/books/12345";
        URL url = new URL(endpointAddress);
        HttpURLConnection connect = (HttpURLConnection)url.openConnection();
        connect.addRequestProperty("Accept", "text/plain,application/xml");
        assertEquals(500, connect.getResponseCode());
        InputStream in = connect.getErrorStream();
        assertNotNull(in);          

        InputStream expected = getClass()
View Full Code Here

       
        String endpointAddress =
            "http://localhost:9080/webapp/bookstore/nonexistent";
        URL url = new URL(endpointAddress);
        HttpURLConnection connect = (HttpURLConnection)url.openConnection();
        connect.addRequestProperty("Accept", "application/xml");
        assertEquals(405, connect.getResponseCode());
        InputStream in = connect.getErrorStream();
        assertNotNull(in);          

        assertEquals("Exception is not mapped correctly",
View Full Code Here

       
       
        url=new URL("http://127.0.0.1:"+connector.getLocalPort()+"/test/dump/info?lines=100");
       
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.addRequestProperty("accept-encoding","gzip");
        connection.connect();
        assertEquals("gzip",connection.getHeaderField("Content-Encoding"));

    }
View Full Code Here

        url=new URL("http://127.0.0.1:"+connector.getLocalPort()+"/test/dump/info?query=foo");
        HttpURLConnection connection = (HttpURLConnection)url.openConnection();
        connection.setRequestMethod("POST");
        connection.setDoOutput(true);
        connection.setDoInput(true);
        connection.addRequestProperty(HttpHeaders.CONTENT_TYPE,MimeTypes.FORM_ENCODED);
        connection.addRequestProperty(HttpHeaders.CONTENT_LENGTH, "10");
        connection.getOutputStream().write("abcd=1234\n".getBytes());
        connection.getOutputStream().flush();
       
        connection.connect();
View Full Code Here

        HttpURLConnection connection = (HttpURLConnection)url.openConnection();
        connection.setRequestMethod("POST");
        connection.setDoOutput(true);
        connection.setDoInput(true);
        connection.addRequestProperty(HttpHeaders.CONTENT_TYPE,MimeTypes.FORM_ENCODED);
        connection.addRequestProperty(HttpHeaders.CONTENT_LENGTH, "10");
        connection.getOutputStream().write("abcd=1234\n".getBytes());
        connection.getOutputStream().flush();
       
        connection.connect();
        String s0=IO.toString(connection.getInputStream());
View Full Code Here

            if (c instanceof HttpURLConnection) {
                HttpURLConnection httpURLConnection = (HttpURLConnection)c;

                if (headers != null && !headers.isEmpty()) {
                    for (Map.Entry<String, String> header : headers.entrySet()) {
                        httpURLConnection.addRequestProperty(header.getKey(), header.getValue());
                    }
                }

                if (!OAuthUtils.isEmpty(requestMethod)) {
                    httpURLConnection.setRequestMethod(requestMethod);
View Full Code Here

                    String headerValue = headerValues.nextElement();

                    if (connection.getRequestProperty(headerName) == null) {
                        connection.setRequestProperty(headerName, headerValue);
                    } else {
                        connection.addRequestProperty(headerName, headerValue);
                    }
                }
            }
        }
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

        String endpointAddress = "http://localhost:" + PORT + "/bookstore/unsupportedcontenttype";
        URL url = new URL(endpointAddress);
        HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
        urlConnection.setReadTimeout(30000); // 30 seconds tops
        urlConnection.setConnectTimeout(30000); // 30 second tops
        urlConnection.addRequestProperty("Content-Type", "MissingSeparator");
        urlConnection.setRequestMethod("POST");
        assertEquals(415, urlConnection.getResponseCode());
    }

    @Test
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.