/** * Specifies the Content-Type header, as a string. * The default implementation calls * {@link #setContentType(Header) setContentType(Header)}. * * @param ctString the new Content-Type header, or * <code>null</code> to unset */ public void setContentType(final String ctString) { Header h = null; if (ctString != null) { h = new BasicHeader(HTTP.CONTENT_TYPE, ctString); } setContentType(h); }
/** * Resolve Content */ protected void resolveContent(HttpEntity entity, HttpRequestBase httpRequest) throws IOException { if (entity != null) { ByteArrayOutputStream os = new ByteArrayOutputStream(); entity.writeTo(os); os.flush(); AbstractHttpEntity httpEntity = new org.apache.http.entity.ByteArrayEntity( os.toByteArray()); os.close(); httpEntity.setContentType(entity.getContentType().toString()); ((HttpEntityEnclosingRequestBase) httpRequest) .setEntity(httpEntity); } }
@Override public void setContentType(final String contentType) { httpEntity.setContentType(contentType); }
/** * Specifies the Content-Type header, as a string. * The default implementation calls * {@link #setContentType(Header) setContentType(Header)}. * * @param ctString the new Content-Type header, or * <code>null</code> to unset */ public void setContentType(final String ctString) { Header h = null; if (ctString != null) { h = new BasicHeader(HTTP.CONTENT_TYPE, ctString); } setContentType(h); }
/** * Specifies the Content-Type header, as a string. * The default implementation calls * {@link #setContentType(Header) setContentType(Header)}. * * @param ctString the new Content-Type header, or * <code>null</code> to unset */ public void setContentType(final String ctString) { Header h = null; if (ctString != null) { h = new BasicHeader(HTTP.CONTENT_TYPE, ctString); } setContentType(h); }
/** * Specifies the Content-Type header, as a string. * The default implementation calls * {@link #setContentType(Header) setContentType(Header)}. * * @param ctString the new Content-Type header, or * {@code null} to unset */ public void setContentType(final String ctString) { Header h = null; if (ctString != null) { h = new BasicHeader(HTTP.CONTENT_TYPE, ctString); } setContentType(h); }
/** * Specifies the Content-Type header, as a string. * The default implementation calls * {@link #setContentType(Header) setContentType(Header)}. * * @param ctString the new Content-Type header, or * {@code null} to unset */ public void setContentType(final String ctString) { Header h = null; if (ctString != null) { h = new BasicHeader(HTTP.CONTENT_TYPE, ctString); } setContentType(h); }
/** * Specifies the Content-Type header, as a string. * The default implementation calls * {@link #setContentType(Header) setContentType(Header)}. * * @param ctString the new Content-Type header, or * <code>null</code> to unset */ public void setContentType(final String ctString) { Header h = null; if (ctString != null) { h = new BasicHeader(HTTP.CONTENT_TYPE, ctString); } setContentType(h); }
/** * Specifies the Content-Type header, as a string. * The default implementation calls * {@link #setContentType(Header) setContentType(Header)}. * * @param ctString the new Content-Type header, or * <code>null</code> to unset */ public void setContentType(final String ctString) { Header h = null; if (ctString != null) { h = new BasicHeader(HTTP.CONTENT_TYPE, ctString); } setContentType(h); }
/** * Specifies the Content-Type header, as a string. * The default implementation calls * {@link #setContentType(Header) setContentType(Header)}. * * @param ctString the new Content-Type header, or * {@code null} to unset */ public void setContentType(final String ctString) { Header h = null; if (ctString != null) { h = new BasicHeader(HTTP.CONTENT_TYPE, ctString); } setContentType(h); }
AbstractHttpEntity entity = null; entity = new ByteArrayEntity(jsonParams.toString().getBytes("UTF8")); entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); httpPost.setEntity(entity);
/** * Specifies the Content-Type header, as a string. * The default implementation calls * {@link #setContentType(Header) setContentType(Header)}. * * @param ctString the new Content-Type header, or * {@code null} to unset */ public void setContentType(final String ctString) { Header h = null; if (ctString != null) { h = new BasicHeader(HTTP.CONTENT_TYPE, ctString); } setContentType(h); }
/** * Specifies the Content-Type header, as a string. * The default implementation calls * {@link #setContentType(Header) setContentType(Header)}. * * @param ctString the new Content-Type header, or * <code>null</code> to unset */ public void setContentType(final String ctString) { Header h = null; if (ctString != null) { h = new BasicHeader(HTTP.CONTENT_TYPE, ctString); } setContentType(h); }
public static String sendComment (String commentString, int taskId, String sessionId, int displayType, String url) throws Exception { Map<String, Object> jsonValues = new HashMap<String, Object>(); jsonValues.put("sessionID", sessionId); jsonValues.put("NewTaskComment", commentString); jsonValues.put("TaskID" , taskId); jsonValues.put("DisplayType" , displayType); JSONObject json = new JSONObject(jsonValues); DefaultHttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url + SEND_COMMENT_ACTION); AbstractHttpEntity entity = new ByteArrayEntity(json.toString().getBytes("UTF8")); entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); post.setEntity(entity); HttpResponse response = client.execute(post); return getContent(response); }
public static String sendComment (String commentString, int taskId, String sessionId, int displayType, String url) throws Exception{ //creating map object to creat Json object from it Map<String, Object> jsonValues = new HashMap<String, Object>(); jsonValues.put("sessionID", sessionId); jsonValues.put("NewTaskComment", commentString); jsonValues.put("TaskID" , taskId); jsonValues.put("DisplayType" , displayType); JSONObject json = new JSONObject(jsonValues); //creating a post request. DefaultHttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url + SEND_COMMENT_ACTION); //setting json object to post request. AbstractHttpEntity entity = new ByteArrayEntity(json.toString().getBytes("UTF8")); entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); post.setEntity(entity); //this is your response: HttpResponse response = client.execute(post); return getContent(response); }
/** * Resolve Content */ protected void resolveContent(HttpEntity entity, HttpRequestBase httpRequest) throws IOException { if (entity != null) { ByteArrayOutputStream os = new ByteArrayOutputStream(); entity.writeTo(os); os.flush(); AbstractHttpEntity httpEntity = new org.apache.http.entity.ByteArrayEntity( os.toByteArray()); os.close(); httpEntity.setContentType(entity.getContentType().toString()); ((HttpEntityEnclosingRequestBase) httpRequest) .setEntity(httpEntity); } }
HttpPost request = new HttpPost(SERVICE_URI + uri); AbstractHttpEntity entity = new AbstractHttpEntity() { public boolean isRepeatable() { return true; } public long getContentLength() { return -1; } public boolean isStreaming() { return false; } public InputStream getContent() throws IOException { throw new UnsupportedOperationException(); } public void writeTo(final OutputStream outstream) throws IOException { Writer writer = new OutputStreamWriter(outstream, "UTF-8"); writer.write(arr, 0, arr.length); writer.flush(); } }; entity.setContentType("application/x-www-form-urlencoded"); entity.setContentEncoding(HTTP.UTF_8); request.setEntity(entity); HttpResponse response = null; InputStream bais = null; String result = null; try { response = client.execute(request); HttpEntity he = response.getEntity(); bais = he.getContent(); result = convertStreamToString(bais); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); }
private void addContentTypeHeaderIfMissing(final HttpEntityEnclosingRequest request) { if (request.getEntity().getContentType() == null) { ((AbstractHttpEntity) request.getEntity()).setContentType( ContentType.APPLICATION_OCTET_STREAM.getMimeType()); } }
private void addContentTypeHeaderIfMissing(HttpEntityEnclosingRequest request) { if (request.getEntity().getContentType() == null) { ((AbstractHttpEntity) request.getEntity()).setContentType( ContentType.APPLICATION_OCTET_STREAM.getMimeType()); } }
/** * @param content the content * @param contentLength the length of the content in bytes. you can provide -1 but be aware that some * users reported Redmine configuration problems that prevent it from processing -1 correctly. * See https://github.com/taskadapter/redmine-java-api/issues/78 for details. * @return the string token of the uploaded item. see {@link Attachment#getToken()} */ public String upload(InputStream content, long contentLength) throws RedmineException { final URI uploadURI = getURIConfigurator().getUploadURI(); final HttpPost request = new HttpPost(uploadURI); final AbstractHttpEntity entity = new InputStreamEntity(content, contentLength); /* Content type required by a Redmine */ entity.setContentType("application/octet-stream"); request.setEntity(entity); final String result = send(request); return parseResponse(result, "upload", input -> JsonInput.getStringNotNull(input, "token")); }