Package org.apache.commons.httpclient.methods

Examples of org.apache.commons.httpclient.methods.PostMethod.addRequestHeader()


   {
      HttpClient client = new HttpClient();
      PostMethod method = new PostMethod(url);
      Base64 base64 = new Base64();
      String base64Credentials = new String(base64.encode("admin:admin".getBytes()));
      method.addRequestHeader(new Header("Authorization", "Basic " + base64Credentials));
     
      int status = client.executeMethod(method);
      if (302 != status) {
          throw new RuntimeException("Initiation failed");
      }
View Full Code Here


      String s = writer.getBuffer().toString();
      System.out.println(s);

      PostMethod method = new PostMethod(url);
      method.addRequestHeader("Content-Type", "application/xml");
      method.setRequestBody(s);
      int status = client.executeMethod(method);
      Assert.assertEquals(200, status);
      foo = (RealFoo) ctx.createUnmarshaller().unmarshal(method.getResponseBodyAsStream());
      Assert.assertEquals(((RealFoo) foo).getName(), "bill");
View Full Code Here

   @Test
   public void testFormResource() throws Exception
   {
      HttpClient client = new HttpClient();
      PostMethod method = new PostMethod(TEST_URI);
      method.addRequestHeader("custom-header", "42");
      method.addParameter(BOOLEAN_VALUE_FIELD, "true");
      method.addParameter(NAME_FIELD, "This is My Name");
      method.addParameter(DOUBLE_VALUE_FIELD, "123.45");
      method.addParameter(LONG_VALUE_FIELD, "566780");
      method.addParameter(INTEGER_VALUE_FIELD, "3");
View Full Code Here

   @Test
   public void testNotAcceptable()
   {
      HttpClient client = new HttpClient();
      PostMethod method = new PostMethod(generateBaseUrl());
      method.addRequestHeader(HttpHeaderNames.ACCEPT, "application/bar");
      try
      {
         method.setRequestEntity(new StringRequestEntity("content", "application/bar", null));
         int status = client.executeMethod(method);
         Assert.assertEquals(status, HttpResponseCodes.SC_NOT_ACCEPTABLE);
View Full Code Here

   @Test
   public void testUnsupportedMediaType()
   {
      HttpClient client = new HttpClient();
      PostMethod method = new PostMethod(generateBaseUrl());
      method.addRequestHeader(HttpHeaderNames.ACCEPT, "application/foo");
      try
      {
         method.setRequestEntity(new StringRequestEntity("content", "text/plain", null));
         int status = client.executeMethod(method);
         Assert.assertEquals(status, HttpResponseCodes.SC_UNSUPPORTED_MEDIA_TYPE);
View Full Code Here

    protected PostMethod executePostXml(String uri, Object object) throws Exception
    {
        HttpClient httpClient = new HttpClient();

        PostMethod postMethod = new PostMethod(uri);
        postMethod.addRequestHeader("Accept", MediaType.APPLICATION_XML.toString());

        StringWriter writer = new StringWriter();
        marshaller.marshal(object, writer);

        RequestEntity entity =
View Full Code Here

        HttpClient httpClient = new HttpClient();
        httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, password));
        httpClient.getParams().setAuthenticationPreemptive(true);

        PostMethod postMethod = new PostMethod(uri);
        postMethod.addRequestHeader("Accept", MediaType.APPLICATION_XML.toString());

        StringWriter writer = new StringWriter();
        marshaller.marshal(object, writer);

        RequestEntity entity =
View Full Code Here

        HttpClient httpClient = new HttpClient();
        httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, password));
        httpClient.getParams().setAuthenticationPreemptive(true);

        PostMethod postMethod = new PostMethod(uri);
        postMethod.addRequestHeader("Accept", MediaType.APPLICATION_XML.toString());

        RequestEntity entity = new StringRequestEntity(string, mediaType, "UTF-8");
        postMethod.setRequestEntity(entity);

        httpClient.executeMethod(postMethod);
View Full Code Here

        HttpClient httpClient = new HttpClient();
        httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, password));
        httpClient.getParams().setAuthenticationPreemptive(true);

        PostMethod postMethod = new PostMethod(uri);
        postMethod.addRequestHeader("Accept", MediaType.APPLICATION_XML.toString());
        postMethod.addRequestHeader("Content-type", MediaType.APPLICATION_WWW_FORM.toString());

        postMethod.setRequestBody(nameValuePairs);

        httpClient.executeMethod(postMethod);
View Full Code Here

        httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, password));
        httpClient.getParams().setAuthenticationPreemptive(true);

        PostMethod postMethod = new PostMethod(uri);
        postMethod.addRequestHeader("Accept", MediaType.APPLICATION_XML.toString());
        postMethod.addRequestHeader("Content-type", MediaType.APPLICATION_WWW_FORM.toString());

        postMethod.setRequestBody(nameValuePairs);

        httpClient.executeMethod(postMethod);
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.