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

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

Introduction

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

Prototype

public void setEntity(final HttpEntity entity) 

Source Link

Usage

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

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

From source file:com.yojiokisoft.japanesecalc.MyUncaughtExceptionHandler.java

/**
 * ?????./* w w w .  j ava2 s . c o m*/
 */
private static void postBugReport() {
    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    String bug = getFileBody(sBugReportFile);
    nvps.add(new BasicNameValuePair("dev", Build.DEVICE));
    nvps.add(new BasicNameValuePair("mod", Build.MODEL));
    nvps.add(new BasicNameValuePair("sdk", String.valueOf(Build.VERSION.SDK_INT)));
    nvps.add(new BasicNameValuePair("ver", sVersionName));
    nvps.add(new BasicNameValuePair("bug", bug));
    try {
        HttpPost httpPost = new HttpPost("http://mrp-bug-report.appspot.com/bug");
        httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
        DefaultHttpClient httpClient = new DefaultHttpClient();
        httpClient.execute(httpPost);
    } catch (IOException e) {
        e.printStackTrace();
    }
    sBugReportFile.delete();
}

From source file:CB_Core.GCVote.GCVote.java

public static ArrayList<RatingData> GetRating(String User, String password, ArrayList<String> Waypoints) {
    ArrayList<RatingData> result = new ArrayList<RatingData>();

    String data = "userName=" + User + "&password=" + password + "&waypoints=";
    for (int i = 0; i < Waypoints.size(); i++) {
        data += Waypoints.get(i);/* ww w. ja v  a2  s .c  om*/
        if (i < (Waypoints.size() - 1))
            data += ",";
    }

    try {
        HttpPost httppost = new HttpPost("http://gcvote.de/getVotes.php");

        httppost.setEntity(new ByteArrayEntity(data.getBytes("UTF8")));

        // Log.info(log, "GCVOTE-Post" + data);

        // Execute HTTP Post Request
        String responseString = Execute(httppost);

        // Log.info(log, "GCVOTE-Response" + responseString);

        DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        InputSource is = new InputSource();
        is.setCharacterStream(new StringReader(responseString));

        Document doc = db.parse(is);

        NodeList nodelist = doc.getElementsByTagName("vote");

        for (Integer i = 0; i < nodelist.getLength(); i++) {
            Node node = nodelist.item(i);

            RatingData ratingData = new RatingData();
            ratingData.Rating = Float.valueOf(node.getAttributes().getNamedItem("voteAvg").getNodeValue());
            String userVote = node.getAttributes().getNamedItem("voteUser").getNodeValue();
            ratingData.Vote = (userVote == "") ? 0 : Float.valueOf(userVote);
            ratingData.Waypoint = node.getAttributes().getNamedItem("waypoint").getNodeValue();
            result.add(ratingData);

        }

    } catch (Exception e) {
        String Ex = "";
        if (e != null) {
            if (e != null && e.getMessage() != null)
                Ex = "Ex = [" + e.getMessage() + "]";
            else if (e != null && e.getLocalizedMessage() != null)
                Ex = "Ex = [" + e.getLocalizedMessage() + "]";
            else
                Ex = "Ex = [" + e.toString() + "]";
        }
        Log.err(log, "GcVote-Error" + Ex);
        return null;
    }
    return result;

}

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

public static HttpResponse startCapturePost(TrustedHttpClient client) throws Exception {
    HttpPost post = new HttpPost(getServiceUrl() + "startCapture");
    List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    params.add(new BasicNameValuePair("config", captureProperties()));
    post.setEntity(new UrlEncodedFormEntity(params));
    return client.execute(post);
}

From source file:org.smartloli.kafka.eagle.common.util.HttpClientUtils.java

/**
 * Send request by post method./*from   w w w.j av a2  s  .  co m*/
 * 
 * @param uri:
 *            http://ip:port/demo
 */
public static String doPostJson(String uri, String data) {
    String result = "";
    try {
        CloseableHttpClient client = null;
        CloseableHttpResponse response = null;
        try {
            HttpPost httpPost = new HttpPost(uri);
            httpPost.setHeader(HTTP.CONTENT_TYPE, "application/json");
            httpPost.setEntity(new StringEntity(data, ContentType.create("text/json", "UTF-8")));
            client = HttpClients.createDefault();
            response = client.execute(httpPost);
            HttpEntity entity = response.getEntity();
            result = EntityUtils.toString(entity);
        } finally {
            if (response != null) {
                response.close();
            }
            if (client != null) {
                client.close();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        LOG.error("Do post json request has error, msg is " + e.getMessage());
    }

    return result;
}

From source file:com.networknt.light.server.handler.loader.MenuLoader.java

private static void loadMenuFile(File file) {
    Scanner scan = null;//w  w  w.  j  av a  2s .  c  o  m
    try {
        scan = new Scanner(file, Loader.encoding);
        // the content is only the data portion. convert to map
        String content = scan.useDelimiter("\\Z").next();
        HttpPost httpPost = new HttpPost("http://injector:8080/api/rs");
        StringEntity input = new StringEntity(content);
        input.setContentType("application/json");
        httpPost.setEntity(input);
        CloseableHttpResponse response = httpclient.execute(httpPost);

        try {
            System.out.println(response.getStatusLine());
            HttpEntity entity = response.getEntity();
            BufferedReader rd = new BufferedReader(new InputStreamReader(entity.getContent()));
            String json = "";
            String line = "";
            while ((line = rd.readLine()) != null) {
                json = json + line;
            }
            System.out.println("json = " + json);
            EntityUtils.consume(entity);
        } finally {
            response.close();
        }
    } catch (IOException ioe) {
        ioe.printStackTrace();
    } finally {
        if (scan != null)
            scan.close();
    }
}

From source file:com.mothsoft.alexis.util.NetworkingUtil.java

public static HttpClientResponse post(final URL url, final List<NameValuePair> params) throws IOException {
    final HttpPost post = new HttpPost(url.toExternalForm());

    UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(params);
    post.setEntity(formEntity);

    post.addHeader("Accept-Charset", "UTF-8");

    final HttpClient client = getClient();
    HttpResponse response = client.execute(post);
    int status = response.getStatusLine().getStatusCode();

    if (status != 200) {
        throw new IOException("status: " + status);
    }/*from ww  w. ja  va 2s. c om*/

    final HttpEntity entity = response.getEntity();
    final InputStream is = entity.getContent();
    final Charset charset = getCharset(entity);

    return new HttpClientResponse(post, status, null, null, is, charset);
}

From source file:com.deployd.Deployd.java

public static JSONObject post(JSONObject input, String uri)
        throws ClientProtocolException, IOException, JSONException {

    HttpPost post = new HttpPost(endpoint + uri);
    HttpClient client = new DefaultHttpClient();
    post.setEntity(new ByteArrayEntity(input.toString().getBytes("UTF8")));
    HttpResponse response = client.execute(post);
    ByteArrayEntity e = (ByteArrayEntity) response.getEntity();
    InputStream is = e.getContent();
    String data = new Scanner(is).next();
    JSONObject result = new JSONObject(data);
    return result;
}

From source file:com.kingmed.dp.aperio.DsClient.java

public static String logon() throws Exception {
    String token = null;//from   ww  w  .  j  a va 2  s. com
    String url = "http://192.168.180.132:86/Aperio.Security/Security2.asmx";
    String body = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns=\"http://www.aperio.com/webservices/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"> <SOAP-ENV:Body> <Logon><Token>leQJYfWQ6wv_tJa6hhBZlWwgrRZ-mDywnfb9F4EfC1752Pt07NZDEGvFNYYPvpxkN0IvPTrPi0M=</Token><LoginName>gzuser</LoginName><Password>gzking</Password></Logon></SOAP-ENV:Body> </SOAP-ENV:Envelope> ";

    HttpClient hc = HttpClients.createDefault();
    HttpPost httpPost = new HttpPost(url);
    httpPost.addHeader("Content-Type", "text/xml;charset=utf-8");
    httpPost.addHeader("SOAPAction", "http://www.aperio.com/webservices/#Logon");
    StringEntity myEntity = new StringEntity(body, ContentType.create("text/xml", "UTF-8"));
    httpPost.setEntity(myEntity);
    System.out.println(myEntity.getContentType());
    System.out.println("Content-Length" + myEntity.getContentLength());
    HttpResponse res = null;
    res = (CloseableHttpResponse) hc.execute(httpPost);
    HttpEntity entity = res.getEntity();
    System.out.println(EntityUtils.toString(entity));

    return token;
}

From source file:edu.si.services.camel.fcrepo.FcrepoIntegrationTest.java

private static void ingest(String pid, Path payload) throws IOException {
    if (!checkObjectExist(pid)) {
        String ingestURI = FEDORA_URI + "/objects/" + pid
                + "?format=info:fedora/fedora-system:FOXML-1.1&ignoreMime=true";

        logger.debug("INGEST URI = {}", ingestURI);

        HttpPost ingest = new HttpPost(ingestURI);
        ingest.setEntity(new ByteArrayEntity(Files.readAllBytes(payload)));
        ingest.setHeader("Content-type", MediaType.TEXT_XML);
        try (CloseableHttpResponse pidRes = httpClient.execute(ingest)) {
            assertEquals("Failed to ingest " + pid + "!", SC_CREATED, pidRes.getStatusLine().getStatusCode());
            logger.info("Ingested test object {}", EntityUtils.toString(pidRes.getEntity()));
        }//from   w  w  w  . j a  v  a 2 s . com
    }
}