Example usage for org.apache.http.client.methods HttpPost HttpPost

List of usage examples for org.apache.http.client.methods HttpPost HttpPost

Introduction

In this page you can find the example usage for org.apache.http.client.methods HttpPost HttpPost.

Prototype

public HttpPost(final String uri) 

Source Link

Usage

From source file:com.squeezeday.marknadskoll.HttpHelper.java

public static String post(String url, List<? extends NameValuePair> parameters)
        throws IOException, HttpException {
    HttpPost request = new HttpPost(url);
    request.setEntity(new UrlEncodedFormEntity(parameters, HTTP.UTF_8));
    return doRequest(request, url, new BasicHttpContext(), true);
}

From source file:dk.ciid.android.infobooth.xml.XMLParser.java

/**
 * Getting XML from URL making HTTP request
 * @param url string/* www.  ja  va2 s.  c o m*/
 * */
public String getXmlFromUrl(String url) {
    String xml = null;

    try {
        // defaultHttpClient
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);

        // this line breaks it
        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        xml = EntityUtils.toString(httpEntity);

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    // return XML*/
    return xml;
}

From source file:dbpedia.provenance.AuthorMetadata.java

public Integer WikiUserEditCount(String sUser) {
    Integer cnt = -1;//from   ww w.  ja  v  a2  s.  c  om
    String url = String.format("http://en.wikipedia.org/w/api.php?action=query&list=users&ususers=" + sUser
            + "&usprop=editcount&format=xml");
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(url);

    try {
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String response = httpclient.execute(httppost, responseHandler);

        String pattern = "editcount=\"(.*)\"";
        Pattern r = Pattern.compile(pattern, Pattern.DOTALL);
        Matcher m = r.matcher(response);
        if (m.find()) {
            cnt = Integer.valueOf(m.group(1));
            // System.out.println("number of edits, user " + sUser + ": " + m.group(1) );
        }
    } catch (Exception ex) {
        System.out.println(ex.getMessage());
    }

    return cnt;
}

From source file:org.opencastproject.remotetest.server.resource.WorkflowResources.java

public static HttpResponse start(TrustedHttpClient client, String mediapackage, String workflowDefinition,
        String properties) throws Exception {
    HttpPost post = new HttpPost(getServiceUrl() + "start");
    List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    params.add(new BasicNameValuePair("mediapackage", mediapackage));
    params.add(new BasicNameValuePair("definition", workflowDefinition));
    params.add(new BasicNameValuePair("properties", properties));
    post.setEntity(new UrlEncodedFormEntity(params));
    return client.execute(post);
}

From source file:com.alignace.chargeio.net.Requestor.java

public ServerResponse post(String url, Map<String, String> headers, String data)
        throws UnsupportedEncodingException {

    HttpPost post = new HttpPost(url);

    for (String key : headers.keySet())
        post.setHeader(key, headers.get(key));

    post.setEntity(new StringEntity(data));
    return executeRequest(post);
}

From source file:org.muckebox.android.net.PreannounceTask.java

@Override
protected Void doInBackground(Integer... trackIds) {
    for (int i = 0; i < trackIds.length; ++i) {
        int trackId = trackIds[i];
        MuckeboxHttpClient httpClient = null;

        try {/*from w ww  . j  av a 2  s. c o  m*/
            String url = ApiHelper.getApiUrl("hint", Integer.toString(trackId),
                    new String[] { "format", "quality" },
                    new String[] { Preferences.getTranscodingType(), Preferences.getTranscodingQuality() });

            httpClient = new MuckeboxHttpClient();
            HttpPost httpPost = new HttpPost(url);

            httpClient.execute(httpPost);
        } catch (IOException e) {
        } finally {
            if (httpClient != null)
                httpClient.destroy();
        }
    }

    return null;
}

From source file:org.brunocvcunha.instagram4j.requests.InstagramPostRequest.java

@Override
public T execute() throws ClientProtocolException, IOException {
    HttpPost post = new HttpPost(InstagramConstants.API_URL + getUrl());
    post.addHeader("Connection", "close");
    post.addHeader("Accept", "*/*");
    post.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    post.addHeader("Cookie2", "$Version=1");
    post.addHeader("Accept-Language", "en-US");
    post.addHeader("User-Agent", InstagramConstants.USER_AGENT);

    log.debug("User-Agent: " + InstagramConstants.USER_AGENT);
    String payload = getPayload();
    log.debug("Base Payload: " + payload);

    if (isSigned()) {
        payload = InstagramHashUtil.generateSignature(payload);
    }/*from   w  w  w .j  a  va2s . c o m*/
    log.debug("Final Payload: " + payload);
    post.setEntity(new StringEntity(payload));

    HttpResponse response = api.getClient().execute(post);
    api.setLastResponse(response);

    int resultCode = response.getStatusLine().getStatusCode();
    String content = EntityUtils.toString(response.getEntity());

    post.releaseConnection();

    return parseResult(resultCode, content);
}

From source file:com.yahoo.wiki.webservice.application.WikiMain.java

/**
 * Makes the dimensions passthrough./*from w w  w .ja va 2  s .c  o  m*/
 * <p>
 * This method sends a lastUpdated date to each dimension in the dimension cache, allowing the health checks
 * to pass without having to set up a proper dimension loader. For each dimension, d, the following query is
 * sent to the /v1/cache/dimensions/d endpoint:
 * {
 *     "name": "d",
 *     "lastUpdated": "2016-01-01"
 * }
 *
 * @param port  The port through which we access the webservice
 *
 * @throws IOException If something goes terribly wrong when building the JSON or sending it
 */
private static void markDimensionCacheHealthy(int port) throws IOException {
    for (DimensionConfig dimensionConfig : new WikiDimensions().getAllDimensionConfigurations()) {
        String dimension = dimensionConfig.getApiName();
        HttpPost post = new HttpPost("http://localhost:" + port + "/v1/cache/dimensions/" + dimension);
        post.setHeader("Content-type", "application/json");
        post.setEntity(new StringEntity(
                String.format("{\n \"name\":\"%s\",\n \"lastUpdated\":\"2016-01-01\"\n}", dimension)));
        CloseableHttpClient client = HttpClientBuilder.create().build();
        CloseableHttpResponse response = client.execute(post);
        LOG.debug("Mark Dimension Cache Updated Response: ", response);
    }
}

From source file:att.jaxrs.client.Content_tagCollection.java

public static Content_tagCollection getContentTagsWithID(long content_id) {
    List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
    urlParameters.add(new BasicNameValuePair("content_id", Long.toString(content_id)));

    Content_tagCollection collectionCT = new Content_tagCollection();

    try {//  w  w w  .j  av  a 2  s.  co  m
        System.out.println("invoking getTagsWithID: " + content_id);
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost post = new HttpPost(Constants.SELECT_WITH_KEY_CONTENT_TAG_RESOURCE);
        post.setEntity(new UrlEncodedFormEntity(urlParameters));
        HttpResponse result = httpClient.execute(post);
        System.out.println(Constants.RESPONSE_STATUS_CODE + result);
        String resultStr = Util.getStringFromInputStream(result);

        collectionCT = Marshal.unmarshal(Content_tagCollection.class, resultStr);

    } catch (Exception e) {
        e.printStackTrace();

    }

    return collectionCT;
}

From source file:ecplugins.s3.TestUtils.java

/**
 * callRunProcedure/*  ww  w. ja  v a2  s . co  m*/
 *
 * @param jo
 * @return the jobId of the job launched by runProcedure
 */
public static String callRunProcedure(JSONObject jo) throws Exception {

    HttpClient httpClient = new DefaultHttpClient();
    JSONObject result = null;

    try {
        HttpPost httpPostRequest = new HttpPost("http://" + props.getProperty(StringConstants.COMMANDER_USER)
                + ":" + props.getProperty(StringConstants.COMMANDER_PASSWORD) + "@"
                + StringConstants.COMMANDER_SERVER + ":8000/rest/v1.0/jobs?request=runProcedure");
        StringEntity input = new StringEntity(jo.toString());

        input.setContentType("application/json");
        httpPostRequest.setEntity(input);
        HttpResponse httpResponse = httpClient.execute(httpPostRequest);

        result = new JSONObject(EntityUtils.toString(httpResponse.getEntity()));
        return result.getString("jobId");

    } finally {
        httpClient.getConnectionManager().shutdown();
    }

}