List of usage examples for org.apache.http.entity StringEntity StringEntity
public StringEntity(String str, Charset charset)
From source file:com.granita.icloudcalsync.webdav.HttpReport.java
HttpReport(URI uri, String entity) { this(uri);// ww w .j a va 2 s .c o m setHeader("Content-Type", "text/xml; charset=UTF-8"); setHeader("Accept", "text/xml"); setHeader("Depth", "1"); try { setEntity(new StringEntity(entity, "UTF-8")); } catch (UnsupportedEncodingException e) { Log.wtf(TAG, "String entity doesn't support UTF-8"); } }
From source file:com.vmware.photon.controller.api.client.resource.ApiBase.java
public static StringEntity serializeObjectAsJson(Object o) throws JsonProcessingException { String payload = objectMapper.writeValueAsString(o); return new StringEntity(payload, ContentType.APPLICATION_JSON); }
From source file:net.nordist.lloydproof.HttpJSONClient.java
public void sendRequest(JSONObject json) throws IOException, JSONException { StringEntity entity = new StringEntity(json.toString(), HTTP.UTF_8); entity.setContentType("application/json"); httpRequest.setEntity(entity);/* w ww . ja v a2 s . c o m*/ httpResponse = httpClient.execute(httpRequest); }
From source file:at.bitfire.davdroid.webdav.HttpReport.java
HttpReport(URI uri, String entity) { setURI(uri);/*from w w w .j ava 2s .c o m*/ setHeader("Content-Type", "text/xml; charset=UTF-8"); setHeader("Depth", "0"); try { setEntity(new StringEntity(entity, "UTF-8")); Log.d(TAG, "Prepared REPORT request for " + uri + ": " + entity); } catch (UnsupportedEncodingException e) { Log.e(TAG, e.getMessage()); } }
From source file:org.smartloli.kafka.eagle.common.util.TestHttpClientUtils.java
private static HttpPost createHttpPost(Map<String, Object> dingDingMarkdownMessage) { if (WEBHOOK_TOKEN == null || WEBHOOK_TOKEN.trim().isEmpty()) { return null; }//from w w w . j a v a 2 s.c o m HttpPost httpPost = new HttpPost(WEBHOOK_TOKEN); httpPost.addHeader("Content-Type", "application/json; charset=utf-8"); StringEntity sEntity = new StringEntity(JSONObject.toJSONString(dingDingMarkdownMessage), "utf-8"); httpPost.setEntity(sEntity); return httpPost; }
From source file:se.vgregion.pubsub.push.impl.HttpUtil.java
public static HttpEntity createEntity(String s) { try {//from ww w .j av a 2 s .c om return new StringEntity(s, "UTF-8"); } catch (UnsupportedEncodingException shouldNeverHappen) { throw new RuntimeException(shouldNeverHappen); } }
From source file:com.wbtech.dao.NetworkUitlity.java
public static MyMessage post(String url, String data) { // TODO Auto-generated method stub String returnContent = ""; MyMessage message = new MyMessage(); HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); try {//from w w w .j a v a2 s.c o m StringEntity se = new StringEntity("content=" + data, HTTP.UTF_8); Log.d("postdata", "content=" + data); se.setContentType("application/x-www-form-urlencoded"); httppost.setEntity(se); HttpResponse response = httpclient.execute(httppost); int status = response.getStatusLine().getStatusCode(); String returnXML = EntityUtils.toString(response.getEntity()); returnContent = URLDecoder.decode(returnXML); switch (status) { case 200: message.setFlag(true); message.setMsg(returnContent); break; default: Log.e("error", status + returnContent); message.setFlag(false); message.setMsg(returnContent); break; } } catch (Exception e) { JSONObject jsonObject = new JSONObject(); if (e.getMessage().equalsIgnoreCase("no route to host")) { try { jsonObject.put("err", "??,???"); returnContent = jsonObject.toString(); message.setFlag(false); message.setMsg(returnContent); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } else if (e.getMessage().equalsIgnoreCase("network unreachable") || e.getMessage().equalsIgnoreCase("www.cobub.com")) { try { jsonObject.put("err", ""); returnContent = jsonObject.toString(); message.setFlag(false); message.setMsg(returnContent); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } else { try { jsonObject.put("err", ""); returnContent = jsonObject.toString(); message.setFlag(false); message.setMsg(returnContent); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } return message; }
From source file:communication.Communicator.java
/** * Adds a new trackingPosition to an existing cartracker * * @param tracker The cartracker with a new trackingPosition * @return The serialnumber of the new trackingPosition * @throws IOException/*from ww w . j av a 2 s.c om*/ */ public static Long postTrackingPositionsForTracker(CarTracker tracker) throws IOException { Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create(); CloseableHttpClient httpClient = HttpClientBuilder.create().build(); HttpPost post = new HttpPost(BASE_URL_PRODUCTION + "/" + tracker.getId() + "/movements"); String jsonBody = gson.toJson(tracker.getCurrentTrackingPeriod()); StringEntity postingString = new StringEntity(jsonBody, CHARACTER_SET); post.setEntity(postingString); post.setHeader(HTTP.CONTENT_TYPE, "application/json"); HttpResponse response = httpClient.execute(post); String responseString = EntityUtils.toString(response.getEntity(), CHARACTER_SET); JSONObject json = new JSONObject(responseString); return json.getLong("serialNumber"); }
From source file:com.yattatech.gcm.format.JsonFormat.java
@Override public HttpEntity getRequest(String registrationId, String message) throws Exception { final JSONObject json = new JSONObject(); final JSONObject data = new JSONObject(); json.element("registration_ids", new String[] { registrationId }); json.element("delay_while_idle", true); data.element("message", message); data.element("time", String.valueOf(System.currentTimeMillis())); data.element("agent", "GCMSenderTest"); json.element("data", data); return new StringEntity(json.toString(), ContentType.create("application/json")); }
From source file:org.esigate.HttpErrorPage.java
private static HttpEntity toMemoryEntity(String content) { return new StringEntity(content, "UTF-8"); }