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.willowtreeapps.uploader.testflight.TestFlightUploader.java

public Map upload(UploadRequest ur) throws IOException, org.json.simple.parser.ParseException {

    DefaultHttpClient httpClient = new DefaultHttpClient();

    HttpHost targetHost = new HttpHost(HOST);
    HttpPost httpPost = new HttpPost(POST);
    FileBody fileBody = new FileBody(ur.file);

    MultipartEntity entity = new MultipartEntity();
    entity.addPart("api_token", new StringBody(ur.apiToken));
    entity.addPart("team_token", new StringBody(ur.teamToken));
    entity.addPart("notes", new StringBody(ur.buildNotes));
    entity.addPart("file", fileBody);

    if (ur.dsymFile != null) {
        FileBody dsymFileBody = new FileBody(ur.dsymFile);
        entity.addPart("dsym", dsymFileBody);
    }/*from   ww  w  .java  2s . c  o m*/

    if (ur.lists.length() > 0) {
        entity.addPart("distribution_lists", new StringBody(ur.lists));
    }

    entity.addPart("notify", new StringBody(ur.notifyTeam ? "True" : "False"));
    entity.addPart("replace", new StringBody(ur.replace ? "True" : "False"));
    httpPost.setEntity(entity);

    return this.send(ur, httpClient, targetHost, httpPost);
}

From source file:io.encoded.jersik.runtime.client.AbstractServiceClient.java

protected <S, T> T execute(String operationName, S request, ObjectCodec<S> requestCodec,
        ObjectCodec<T> responseCodec) throws IOException {
    URI operationUri = serviceUri.resolve(operationName);
    HttpPost post = new HttpPost(operationUri);
    post.setEntity(new RequestEntity<S>(request, requestCodec, JsonCodec.INSTANCE));
    HttpResponse httpResponse = httpClient.execute(post);
    StatusLine statusLine = httpResponse.getStatusLine();
    if (statusLine.getStatusCode() != HttpStatus.SC_OK) {
        consume(httpResponse.getEntity());
        throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
    }//from   w ww .ja v  a 2 s  .  c o m
    return JsonCodec.INSTANCE.decode(httpResponse.getEntity().getContent(), responseCodec);
}

From source file:es.upm.fiware.rss.settlement.SettlementNotifier.java

public void notifyProvider() {
    // Makes a POST request to the specified callback URL
    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost(this.pool.getCallbackUrl());
    post.setHeader("Content-type", MediaType.APPLICATION_JSON);

    Map<String, String> data = new HashMap<>();
    data.put("status", pool.getState().toString());

    try {//from ww  w.ja  v  a  2s  .c o  m
        HttpEntity entity = new StringEntity(new JSONObject(data).toString());
        post.setEntity(entity);

        // A failure in the notification must not block the system
        client.execute(post);
    } catch (UnsupportedEncodingException ex) {
        Logger.getLogger(SettlementNotifier.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(SettlementNotifier.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:fr.shywim.antoinedaniel.utils.GcmUtils.java

public static void sendRegistrationIdToBackend(Context context, String regid, int version) {
    try {/*w w  w . j  ava  2s .c o m*/
        HttpPost post = new HttpPost(context.getString(R.string.api_register));
        List<NameValuePair> params = new ArrayList<>(2);
        params.add(new BasicNameValuePair("regid", regid));
        params.add(new BasicNameValuePair("version", Integer.toString(version)));
        post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));

        HttpClient client = new DefaultHttpClient();
        HttpResponse response = client.execute(post);

        int responseCode = response.getStatusLine().getStatusCode();
        if (responseCode == 200 || responseCode == 201) {
            context.getSharedPreferences(AppConstants.GOOGLE_PREFS, Context.MODE_PRIVATE).edit()
                    .putBoolean(AppConstants.GOOGLE_GCM_REGISTERED, true).apply();
        }
    } catch (IOException e) {
        Crashlytics.logException(e);
    }
}

From source file:eu.seaclouds.platform.dashboard.http.HttpPostRequestBuilder.java

public HttpPostRequestBuilder uri(String uri) {
    this.requestBase = new HttpPost(uri);
    return this;
}

From source file:net.ecfirm.ec.ec1.net.EcNetHttpPost.java

@Override
/**/*from   w  w  w.j  av  a2  s .com*/
 * @TODO test: params type trans from jsonobject to hashmap */
protected InputStream httpPost() throws IOException {
    InputStream inputStream = null;
    DefaultHttpClient httpClient = EcNetHelper.getHttpClient();
    HttpPost httpPost = new HttpPost(url);
    List<NameValuePair> nvps = new ArrayList<>();
    Iterator<String> iter = this.params.keySet().iterator(); //this.params.keys();
    String key, value = "";
    while (iter.hasNext()) {
        key = iter.next(); //app.log(this.getClass().getSimpleName() + ".httpPost", "key: " + key);
        try {
            value = params.get(key);
        } catch (Exception e) {
            app.log(e);
        } //app.log(this.getClass().getSimpleName() + ".httpPost", "value: // " + value);
        nvps.add(new BasicNameValuePair(key, value));
    }
    try {
        httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
    } catch (UnsupportedEncodingException e) {
        e.getMessage();
    }
    try {
        HttpResponse response = httpClient.execute(httpPost);
        HttpEntity entity = response.getEntity();
        inputStream = entity.getContent();
        if (EcConst.DEBUG)
            net.getCookieLog(this.getClass().getSimpleName());
    }
    //catch(ConnectTimeoutException e) { app.log(e); }
    //catch(ClientProtocolException e)   { app.log(e); }
    //catch(IOException e)   { app.log(e); }
    catch (Exception e) {
        app.log(e);
    }
    return inputStream;
}

From source file:grandroid.geo.MapRoute.java

public Document getDocument(LatLng start, LatLng end, String mode) {
    String url = "http://maps.googleapis.com/maps/api/directions/xml?" + "origin=" + start.latitude + ","
            + start.longitude + "&destination=" + end.latitude + "," + end.longitude
            + "&sensor=false&units=metric&mode=" + mode;

    try {//  w w w  .  j a  v  a  2 s. c o m
        HttpClient httpClient = new DefaultHttpClient();
        HttpContext localContext = new BasicHttpContext();
        HttpPost httpPost = new HttpPost(url);
        HttpResponse response = httpClient.execute(httpPost, localContext);
        InputStream in = response.getEntity().getContent();
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.parse(in);
        return doc;
    } catch (Exception e) {
        Log.e("grandroid", null, e);
    }
    return null;
}

From source file:javafxapplication1.HttpClientExample.java

private void sendPost() throws Exception {

    String url = "https://selfsolve.apple.com/wcResults.do";

    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost(url);

    // add header
    post.setHeader("User-Agent", USER_AGENT);

    List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
    urlParameters.add(new BasicNameValuePair("sn", "C02G8416DRJM"));
    urlParameters.add(new BasicNameValuePair("cn", ""));
    urlParameters.add(new BasicNameValuePair("locale", ""));
    urlParameters.add(new BasicNameValuePair("caller", ""));
    urlParameters.add(new BasicNameValuePair("num", "12345"));

    post.setEntity(new UrlEncodedFormEntity(urlParameters));

    HttpResponse response = client.execute(post);
    System.out.println("\nSending 'POST' request to URL : " + url);
    System.out.println("Post parameters : " + post.getEntity());
    System.out.println("Response Code : " + response.getStatusLine().getStatusCode());

    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

    StringBuffer result = new StringBuffer();
    String line = "";
    while ((line = rd.readLine()) != null) {
        result.append(line);/*from   ww w .j av  a2 s  .  c  o  m*/
    }

    System.out.println(result.toString());

}

From source file:com.google.developers.gdgfirenze.mockep.AndroidSimulator.java

private static void postData(String url, JSONObject jsonSamplePacket)
        throws ClientProtocolException, IOException {

    HttpParams myParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(myParams, 10000);
    HttpConnectionParams.setSoTimeout(myParams, 10000);
    HttpClient httpclient = new DefaultHttpClient(myParams);

    HttpPost httppost = new HttpPost(url.toString());
    httppost.setHeader("Content-type", "application/json");

    StringEntity se = new StringEntity(jsonSamplePacket.toString());
    se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
    httppost.setEntity(se);//from w ww  .j av a2s .com

    HttpResponse response = httpclient.execute(httppost);

    String temp = EntityUtils.toString(response.getEntity());
    System.out.println("JSON post response: " + temp);
}

From source file:org.fcrepo.auth.oauth.integration.api.TokenEndpointIT.java

@Test
public void testGetToken() throws Exception {
    logger.trace("Entering testGetToken()...");
    final HttpPost post = new HttpPost(
            tokenEndpoint + "?grant_type=password&username=foo&password=bar&client_secret=foo&client_id=bar");
    post.addHeader("Accept", APPLICATION_JSON);
    post.addHeader("Content-type", APPLICATION_FORM_URLENCODED);
    final HttpResponse tokenResponse = client.execute(post);
    logger.debug("Got a token response: \n{}", EntityUtils.toString(tokenResponse.getEntity()));
    assertEquals("Couldn't retrieve a token from token endpoint!", 200,
            tokenResponse.getStatusLine().getStatusCode());

}