Package org.apache.http.client.methods

Examples of org.apache.http.client.methods.HttpPost.addHeader()


            Logger.info("Creating comm");
            HttpPost request = new HttpPost(Application.baseRestUrl + "/communities");
            request.setHeader("Accept", "application/json");
            request.addHeader("Content-Type", "application/json");
            String token = session("userToken");
            request.addHeader("rest-dspace-token", token);


            Community community = form(Community.class).bindFromRequest().get();

            StringEntity communityEntity = new StringEntity("{\"name\":\""+ community.name +"\"}");
View Full Code Here


            //StringEntity params =new StringEntity("{\"email\":\"admin@dspace.org\",\"password\":\"s3cret\"} ");
            DynamicForm requestData = Form.form().bindFromRequest();
            String email = requestData.get("email");
            String password = requestData.get("password");
            StringEntity params =new StringEntity("{\"email\":\"" + email + "\",\"password\":\"" + password + "\"}");
            request.addHeader("content-type", "application/json");
            request.setEntity(params);
            HttpResponse response = httpClient.execute(request);

            if(response.getStatusLine().getStatusCode() == 200) {
                String responseBody = EntityUtils.toString(response.getEntity());
View Full Code Here

                .getSchemeRegistry().getScheme("https").getSocketFactory();
        sf.setHostnameVerifier(new AllowAllHostnameVerifier());

        try {
            HttpPost request = new HttpPost(baseRestUrl + "/logout");
            request.addHeader("Content-Type", "application/json");
            String token = session("userToken");
            request.addHeader("rest-dspace-token", token);
            HttpResponse response = httpClient.execute(request);

            session().remove("userEmail");
View Full Code Here

        try {
            HttpPost request = new HttpPost(baseRestUrl + "/logout");
            request.addHeader("Content-Type", "application/json");
            String token = session("userToken");
            request.addHeader("rest-dspace-token", token);
            HttpResponse response = httpClient.execute(request);

            session().remove("userEmail");
            session().remove("userFullname");
            session().clear();
View Full Code Here

   */
  public String makePostRequest(String url, String jsonPayload) {
    try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
      HttpPost post = new HttpPost(url);
      post.setEntity(new StringEntity(jsonPayload, "utf-8"));
      post.addHeader("Content-Type", "application/json; charset=utf-8");

      return httpClient.execute(post, new BasicResponseHandler());
    } catch (IOException e) {
      throw new LogCommunicationException("Error making POST request to " + url, e);
    }
View Full Code Here

        if (MapUtils.isNotEmpty(definition.getHeaders())) {
            for (Map.Entry<String, String> entry : definition.getHeaders().entrySet()) {
                String effectiveValue = entry.getValue();
                effectiveValue = ActionPlaceholders.substituteNode(effectiveValue, nodeAddress);
                effectiveValue = ActionPlaceholders.substituteExecution(effectiveValue, scheduleExecutionId);
                request.addHeader(entry.getKey(), effectiveValue);
            }
        }

        if (MapUtils.isNotEmpty(definition.getPostParams())) {
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
View Full Code Here

            LinkedList<NameValuePair> postParams = new LinkedList<NameValuePair>();
            if (streams == null || isMultipart) {
              HttpPost post = new HttpPost(url);
              post.setHeader("Content-Charset", "UTF-8");
              if (!isMultipart) {
                post.addHeader("Content-Type",
                    "application/x-www-form-urlencoded; charset=UTF-8");
              }

              List<FormBodyPart> parts = new LinkedList<FormBodyPart>();
              Iterator<String> iter = params.getParameterNamesIterator();
View Full Code Here

    @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

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

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.