Package org.apache.http.client.methods

Examples of org.apache.http.client.methods.HttpPost


     *
     * @throws IOException
     */
    @Test
    public void testLanguageEnglishGiven() throws IOException {
        HttpPost post = new HttpPost(uri("/context/httpheaders/language"));
        post.setHeader("Content-Type", "text/plain");
        post.setEntity(new StringEntity("Hello world!", "UTF-8"));
        post.addHeader("Content-Language", "en");

        final HttpResponse response = client.execute(post);
        assertEquals(response.getStatusLine().getStatusCode(), 200);
        String responseBody = asString(response);
        assertEquals("language:en:", responseBody);
View Full Code Here


     *
     * @throws IOException
     */
    @Test
    public void testLanguageChineseGiven() throws IOException {
        HttpPost post = new HttpPost(uri("/context/httpheaders/language"));
        post.setHeader("Content-Type", "text/plain");
        post.setEntity(new StringEntity("Hello world!", "UTF-8"));
        post.addHeader("Content-Language", "zh");

        final HttpResponse response = client.execute(post);
        assertEquals(response.getStatusLine().getStatusCode(), 200);
        String responseBody = asString(response);
        assertEquals("language:zh:", responseBody);
View Full Code Here

     *
     * @throws IOException
     */
    @Test
    public void testCookiesNone() throws IOException {
        HttpPost HttpPost = new HttpPost(uri("/context/httpheaders/cookies"));

        final HttpResponse response = client.execute(HttpPost);
        assertEquals(response.getStatusLine().getStatusCode(), 200);
        String responseBody = asString(response);
        assertEquals("cookies:", responseBody);
View Full Code Here

     *
     * @throws IOException
     */
    @Test
    public void testCookiesOneGiven() throws IOException {
        final HttpPost HttpPost = new HttpPost(uri("/context/httpheaders/cookies"));
        HttpPost.addHeader("Cookie", "foo=bar");
        final HttpResponse response = client.execute(HttpPost);
        assertEquals(response.getStatusLine().getStatusCode(), 200);
        String responseBody = asString(response);
        assertEquals("cookies:foo=bar:", responseBody);
    }
View Full Code Here

     *
     * @throws IOException
     */
    @Test
    public void testCookiesManyGiven() throws IOException {
        final HttpPost post = new HttpPost(uri("/context/httpheaders/cookies"));
        post.addHeader("Cookie", "foo=bar");
        post.addHeader("Cookie", "foo2=bar2");

        final HttpResponse response = client.execute(post);
        assertEquals(response.getStatusLine().getStatusCode(), 200);
        String responseBody = asString(response);
        assertEquals("cookies:foo=bar:foo2=bar2:", responseBody);
View Full Code Here

        }
    }
   
    @Test
    public void testPostBody() throws Exception {
        HttpUriRequest method = new HttpPost("http://localhost:" + portNum + "/users");

        List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
        urlParameters.add(new BasicNameValuePair("foo", "bar"));

        ((HttpEntityEnclosingRequestBase)method).setEntity(new UrlEncodedFormEntity(urlParameters));
View Full Code Here

  */
  public String performAPIPostOperation(String apiURL, int expectedResponse, String input)
    throws Exception
  {
    DefaultHttpClient client = new DefaultHttpClient();
    HttpPost method = new HttpPost(apiURL);
    try
    {
      method.setEntity(new StringEntity(input,ContentType.create("text/plain","UTF-8")));
      HttpResponse response = client.execute(method);
      int responseCode = response.getStatusLine().getStatusCode();
      String responseString = convertToString(response);
      if (responseCode != expectedResponse)
        throw new Exception("API http error; expected "+Integer.toString(expectedResponse)+", saw "+Integer.toString(responseCode)+": "+responseString);
      // We presume that the data is utf-8, since that's what the API uses throughout.
      return responseString;
    }
    finally
    {
      method.abort();
    }
  }
View Full Code Here

  }

  @Before
  public void setUp() {
    httpClient = new DefaultHttpClient();
    postRequest = new HttpPost("http://0.0.0.0:" + selectedPort);
  }
View Full Code Here

        }
    }
   
    @Test
    public void testPostBody() throws Exception {
        HttpUriRequest method = new HttpPost("http://localhost:" + portNum + "/users");

        List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
        urlParameters.add(new BasicNameValuePair("foo", "bar"));

        ((HttpEntityEnclosingRequestBase)method).setEntity(new UrlEncodedFormEntity(urlParameters));
View Full Code Here

            }
        };
    }
   
    private void getCustomResponse(String address) throws Exception {
        HttpResponse response = doExecute(new HttpPost("http://localhost:" + portNum + address));
        assertHttpResponse(response, 417, "application/JSON");
        assertEquals("Get a wrong http header", "Cache-Control: max-age=20", response.getFirstHeader(HeaderConstants.HEADER_CACHE_CONTROL).toString());
    }
View Full Code Here

TOP

Related Classes of org.apache.http.client.methods.HttpPost

Copyright © 2018 www.massapicom. 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.