Package java.net

Examples of java.net.HttpURLConnection.addRequestProperty()


            h.check(true);
          }    

        try
          {
            conn.addRequestProperty(null, "dddd");
            h.check(false);
          }
        catch (NullPointerException e)
          {
            h.check(true);
View Full Code Here


            h.check(false);
          }

        try
          {
            conn.addRequestProperty("ssss", "dddd");
            h.check(false);
          }
        catch (IllegalStateException e)
          {
            h.check(true);
View Full Code Here

        try
          {
            // if already connected the IllegalStateException
            // must take precedence over the NPE
            conn.addRequestProperty(null, "dddd");
            h.check(false);
          }
        catch (IllegalStateException e)
          {
            h.check(true);
View Full Code Here

        URL url = new URL("http://localhost:8080/foo");      
        HttpURLConnection httpConn = (HttpURLConnection)url.openConnection();
       
        String authenticationString = "Basic " + B64Code.encode( "humpty" + ":" + "dumpty", StringUtil.__ISO_8859_1);
        httpConn.setRequestMethod("POST");
        httpConn.addRequestProperty("foo", "fooValue");
        httpConn.addRequestProperty("Authorization", authenticationString);
        assertEquals(200, httpConn.getResponseCode());
        assertEquals("barValue", httpConn.getHeaderField("bar"));
        InputStream is = httpConn.getInputStream();
        String result = IO.toString(is);
View Full Code Here

        HttpURLConnection httpConn = (HttpURLConnection)url.openConnection();
       
        String authenticationString = "Basic " + B64Code.encode( "humpty" + ":" + "dumpty", StringUtil.__ISO_8859_1);
        httpConn.setRequestMethod("POST");
        httpConn.addRequestProperty("foo", "fooValue");
        httpConn.addRequestProperty("Authorization", authenticationString);
        assertEquals(200, httpConn.getResponseCode());
        assertEquals("barValue", httpConn.getHeaderField("bar"));
        InputStream is = httpConn.getInputStream();
        String result = IO.toString(is);
        is.close();
View Full Code Here

    try {
      String agent = "Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9.2.16) Gecko/20110323 Ubuntu/10.10 (maverick) Firefox/3.6.16,gzip(gfe)";
     
      HttpURLConnection connection = (HttpURLConnection) url.openConnection();
      connection.setRequestProperty("User-Agent", agent);
      connection.addRequestProperty("Cache-Control", "no-cache,max-age=0");
      connection.setReadTimeout(10000);
      connection.setConnectTimeout(10000);
     
      BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "ISO-8859-1"));
      String line;
View Full Code Here

            for (String key : requestHeaders) {
                for (int i = 0, n = requestHeaders.getLength(key); i < n; i++) {
                    if (i == 0) {
                        connection.setRequestProperty(key, requestHeaders.get(key, i));
                    } else {
                        connection.addRequestProperty(key, requestHeaders.get(key, i));
                    }
                }
            }

            // Set the input/output state
View Full Code Here

      UUID uuid = UUID.randomUUID();

      if (_attachmentInputs > 0) {
        // note that we have to add the request property (header) before
        // we get the output stream
        httpConnection.addRequestProperty("Content-Type",
                                          "multipart/related; " +
                                          "type=\"text/xml\"; " +
                                          "boundary=\"uuid:" + uuid + "\"");

        httpOut = httpConnection.getOutputStream();
View Full Code Here

        // TEST
        HttpURLConnection httpURLConnection = (HttpURLConnection) new URL("http://localhost:" + tomcat.getConnector().getPort() + "/test")
                .openConnection();
        String expectedRemoteAddr = "my-remote-addr";
        httpURLConnection.addRequestProperty("x-forwarded-for", expectedRemoteAddr);
        httpURLConnection.addRequestProperty("x-forwarded-proto", "https");

        // VALIDATE

        Assert.assertEquals(HttpURLConnection.HTTP_OK, httpURLConnection.getResponseCode());
View Full Code Here

        // TEST
        HttpURLConnection httpURLConnection = (HttpURLConnection) new URL("http://localhost:" + tomcat.getConnector().getPort() + "/test")
                .openConnection();
        String expectedRemoteAddr = "my-remote-addr";
        httpURLConnection.addRequestProperty("x-forwarded-for", expectedRemoteAddr);
        httpURLConnection.addRequestProperty("x-forwarded-proto", "https");

        // VALIDATE

        Assert.assertEquals(HttpURLConnection.HTTP_OK, httpURLConnection.getResponseCode());
        HttpServletRequest request = mockServlet.getRequest();
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.