Package org.apache.http.client.methods

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


          case GET:
            meth = new HttpGet(url);

            break;
          case POST:
            meth = new HttpPost(url);
            break;
          case DELETE:
            meth = new HttpDelete(url);
            break;
          case PUT:
View Full Code Here


                case DELETE:
                    httpMethod = new HttpDelete(url);
                    break;

                case POST:
                    httpMethod = new HttpPost(url);
                    ((HttpPost) httpMethod).setEntity(new StringEntity(this.requestBody));
                    break;
                case PUT:
                    httpMethod = new HttpPut(url);
                    ((HttpPut) httpMethod).setEntity(new StringEntity(this.requestBody));
View Full Code Here

            throw new RuntimeException("Unable to add note", e);
        }
    }
   
    public Long addNoteWithImage(String note, File imageFile) throws Exception {
        HttpPost request = new HttpPost(DailyMileUtil.ENTRIES_URL);
        HttpResponse response = null;
        try {
            MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
            mpEntity.addPart("media[data]",
                    new FileBody(imageFile, "image/jpeg"));
            mpEntity.addPart("media[type]", new StringBody("image"));
            mpEntity.addPart("message", new StringBody(note));
            mpEntity.addPart("[share_on_services][facebook]", new StringBody("false"));
            mpEntity.addPart("[share_on_services][twitter]", new StringBody("false"));
            mpEntity.addPart("oauth_token", new StringBody(oauthToken));

            request.setEntity(mpEntity);
            // send the request
            response = httpClient.execute(request);
            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode == 401) {
                throw new RuntimeException("unable to execute POST - url: "
View Full Code Here

        return doAuthenticatedPost(DailyMileUtil.ENTRIES_URL, json);
    }

   
    private Long doAuthenticatedPost(String url, String body) throws Exception {
        HttpPost request = new HttpPost(url + "?oauth_token=" + oauthToken);
        HttpResponse response = null;
        try {
            HttpEntity entity = new StringEntity(body, HTTP.UTF_8);
            // set the content type to json
            request.setHeader("Content-Type", "application/json; charset=utf-8");
            request.setEntity(entity);
            // sign the request
            // send the request
            response = httpClient.execute(request);
            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode == 401) {
View Full Code Here

  public static Boolean getRequestPost(String URLPath, StringEntity input) throws Exception {
        String URL = URLBase + URLPath;
        Boolean response =  false;
        DefaultHttpClient httpclient = new DefaultHttpClient();
        try {
          HttpPost httpPost = new HttpPost(URL);
          System.out.println(URL);
            UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
            BasicScheme scheme = new BasicScheme();
            Header authorizationHeader = scheme.authenticate(credentials, httpPost);
            httpPost.setHeader(authorizationHeader);
            httpPost.setEntity(input);
            //System.out.println("Executing request: " + httpGet.getRequestLine());
            //System.out.println(response);
//            response = httpclient.execute(httpGet,responseHandler);
            HttpResponse responseRequest = httpclient.execute(httpPost);
           
View Full Code Here

    {
        String effectiveUrl = definition.getUrl();
        effectiveUrl = ActionPlaceholders.substituteNode(effectiveUrl, nodeAddress);
        effectiveUrl = ActionPlaceholders.substituteExecution(effectiveUrl, scheduleExecutionId);

        HttpPost request = new HttpPost(effectiveUrl);

        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>();
            for (Map.Entry<String, String> entry : definition.getPostParams().entrySet()) {
                String effectiveValue = entry.getValue();
                effectiveValue = ActionPlaceholders.substituteNode(effectiveValue, nodeAddress);
                effectiveValue = ActionPlaceholders.substituteExecution(effectiveValue, scheduleExecutionId);

                NameValuePair nameValuePair = new BasicNameValuePair(entry.getKey(), effectiveValue);
                nameValuePairs.add(nameValuePair);
            }

            HttpEntity encodedFormEntity = new UrlEncodedFormEntity(nameValuePairs, Consts.UTF_8);
            request.setEntity(encodedFormEntity);
        }

        return request;
    }
View Full Code Here

        });
        HttpContext context = new BasicHttpContext();

        String s = "http://localhost:" + port;
        HttpPost httppost = new HttpPost(s);
        httppost.setEntity(new InputStreamEntity(
                new ByteArrayInputStream(
                        new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 } ),
                        -1));

        try {
View Full Code Here

            }
            boolean isMultipart = (this.useMultiPartPost || ( streams != null && streams.size() > 1 )) && !hasNullStreamName;
           
            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();
              while (iter.hasNext()) {
                String p = iter.next();
                String[] vals = params.getParams(p);
                if (vals != null) {
                  for (String v : vals) {
                    if (isMultipart) {
                      parts.add(new FormBodyPart(p, new StringBody(v, Charset.forName("UTF-8"))));
                    } else {
                      postParams.add(new BasicNameValuePair(p, v));
                    }
                  }
                }
              }

              if (isMultipart && streams != null) {
                for (ContentStream content : streams) {
                  String contentType = content.getContentType();
                  if(contentType==null) {
                    contentType = "application/octet-stream"; // default
                  }
                  String contentName = content.getName();
                  parts.add(new FormBodyPart(contentName,
                       new InputStreamBody(
                           content.getStream(),
                           contentType,
                           content.getName())));
                }
              }
             
              if (parts.size() > 0) {
                ModifiedMultipartEntity entity = new ModifiedMultipartEntity(HttpMultipartMode.STRICT, null, UTF8_CHARSET);
                for(FormBodyPart p: parts) {
                  entity.addPart(p);
                }
                post.setEntity(entity);
              } else {
                //not using multipart
                post.setEntity(new UrlEncodedFormEntity(postParams, "UTF-8"));
              }

              method = post;
            }
            // It is has one stream, it is the post body, put the params in the URL
            else {
              String pstr = ClientUtils.toQueryString(params, false);
              HttpPost post = new HttpPost(url + pstr);

              // Single stream as body
              // Using a loop just to get the first one
              final ContentStream[] contentStream = new ContentStream[1];
              for (ContentStream content : streams) {
                contentStream[0] = content;
                break;
              }
              if (contentStream[0] instanceof RequestWriter.LazyContentStream) {
                post.setEntity(new InputStreamEntity(contentStream[0].getStream(), -1) {
                  @Override
                  public Header getContentType() {
                    return new BasicHeader("Content-Type", contentStream[0].getContentType());
                  }
                 
                  @Override
                  public boolean isRepeatable() {
                    return false;
                  }
                 
                });
              } else {
                post.setEntity(new InputStreamEntity(contentStream[0].getStream(), -1) {
                  @Override
                  public Header getContentType() {
                    return new BasicHeader("Content-Type", contentStream[0].getContentType());
                  }
                 
View Full Code Here

        break;
      case FormData.SUBMITMETHOD_POST:
        if (Logging.connectors.isDebugEnabled())
          Logging.connectors.debug("WEB: Post method for '"+urlPath+"'");
        // MUST be just the path, or apparently we wind up resetting the HostConfiguration
        HttpPost postMethod = new HttpPost(urlPath);
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();

        // Add parameters to post variables
        if (formData != null)
        {
          Iterator iter = formData.getElementIterator();
          while (iter.hasNext())
          {
            FormDataElement e = (FormDataElement)iter.next();
            String param = e.getElementName();
            String value = e.getElementValue();
            if (Logging.connectors.isDebugEnabled())
              Logging.connectors.debug("WEB: Post parameter name '"+param+"' value '"+value+"' for '"+urlPath+"'");
            nvps.add(new BasicNameValuePair(param,value));
          }
        }
        try
        {
          postMethod.setEntity(new UrlEncodedFormEntity(nvps,HTTP.UTF_8));
        }
        catch (java.io.UnsupportedEncodingException e)
        {
          throw new ManifoldCFException("Unsupported UTF-8 encoding: "+e.getMessage(),e);
        }
View Full Code Here

        this.localServer.register("*", new BasicRedirectService(host, port));

        DefaultHttpClient client = new DefaultHttpClient();
        HttpContext context = new BasicHttpContext();

        HttpPost httppost = new HttpPost("/oldlocation/");
        httppost.setEntity(new StringEntity("stuff"));

        HttpResponse response = client.execute(getServerHttp(), httppost, context);
        EntityUtils.consume(response.getEntity());

        HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
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.