List of usage examples for org.apache.http.client.utils URLEncodedUtils CONTENT_TYPE
String CONTENT_TYPE
To view the source code for org.apache.http.client.utils URLEncodedUtils CONTENT_TYPE.
Click Source Link
From source file:org.mariotaku.twidere.util.httpclient.UrlEncodedFormEntity.java
/** * Constructs a new {@link UrlEncodedFormEntity} with the list of parameters * in the specified encoding.//from w ww . jav a 2s. c om * * @param parameters list of name/value pairs * @param encoding encoding the name/value pairs be encoded with * @throws UnsupportedEncodingException if the encoding isn't supported */ public UrlEncodedFormEntity(final HttpParameter[] params) throws UnsupportedEncodingException { super(HttpParameter.encodeParameters(params), HTTP.DEFAULT_CONTENT_CHARSET); setContentType(URLEncodedUtils.CONTENT_TYPE + HTTP.CHARSET_PARAM + HTTP.DEFAULT_CONTENT_CHARSET); }
From source file:com.strato.hidrive.api.connection.httpgateway.request.PostRequest.java
@SuppressWarnings("unchecked") protected HttpRequestBase createHttpRequest(String requestUri, HttpRequestParamsVisitor<?> visitor) throws UnsupportedEncodingException { HttpPost httpPost = new HttpPost(requestUri); //There used StringEntity and some string manipulations instead of UrlEncodedFormEntity due to problem in url encoding ("+" instead "%20") //details: http://stackoverflow.com/questions/7915029/how-to-encode-space-as-20-in-urlencodedformentity-while-executing-apache-httppo String entityValue = URLEncodedUtils.format((List<NameValuePair>) visitor.getHttpRequestParams(), HTTP.UTF_8);//from w w w. ja v a2 s. c om entityValue = entityValue.replaceAll("\\+", "%20"); StringEntity entity = new StringEntity(entityValue, HTTP.UTF_8); entity.setContentType(URLEncodedUtils.CONTENT_TYPE); httpPost.setEntity(entity); //original code: //httpPost.setEntity(new UrlEncodedFormEntity((List<? extends NameValuePair>) visitor.getHttpRequestParams(), HTTP.UTF_8)); return httpPost; }
From source file:org.cryptable.pki.communication.http.PKIHTTPCommunication.java
public byte[] sendReceiveMsg(byte[] msg) throws IOException { httpPost.addHeader(URLEncodedUtils.CONTENT_TYPE, "application/pkixcmp"); httpPost.setEntity(new ByteArrayEntity(msg)); HttpResponse httpResponse = httpClient.execute(httpPost); InputStream inputStream = httpResponse.getEntity().getContent(); byte[] byteResponse = new byte[(int) httpResponse.getEntity().getContentLength()]; inputStream.read(byteResponse);/* w ww .ja v a 2s .c om*/ return byteResponse; }
From source file:betting.JsonEntity.java
/** * Constructs a new {@link JsonEntity} with the list of parameters in the * specified encoding.//w w w.ja v a 2s. c o m * * @param parameters * list of name/value pairs * @param charset * encoding the name/value pairs be encoded with * @throws UnsupportedEncodingException * if the encoding isn't supported */ public JsonEntity(final List<? extends NameValuePair> parameters, final String charset) throws UnsupportedEncodingException { super(listToJson(parameters), ContentType.create(URLEncodedUtils.CONTENT_TYPE, charset)); }
From source file:betting.JsonEntity.java
/** * Constructs a new {@link JsonEntity} with the list of parameters in the * specified encoding./*from w w w . jav a 2 s . c o m*/ * * @param parameters * iterable collection of name/value pairs * @param charset * encoding the name/value pairs be encoded with * * @since 4.2 */ public JsonEntity(final Iterable<? extends NameValuePair> parameters, final Charset charset) { super(URLEncodedUtils.format(parameters, charset != null ? charset : HTTP.DEF_CONTENT_CHARSET), ContentType.create(URLEncodedUtils.CONTENT_TYPE, charset)); }
From source file:org.limewire.activation.impl.ActivationCommunicatorImpl.java
String sendToServer(String queryStringToPost, String key, RequestType type) throws IOException { String submitUrl = activationSettings.getActivationHost(); HttpEntity postContent = new StringEntity(queryStringToPost); HttpPost httpPost = new HttpPost(getQueryString(submitUrl, type, key)); httpPost.addHeader("Connection", "close"); httpPost.addHeader("Content-Type", URLEncodedUtils.CONTENT_TYPE); httpPost.setEntity(postContent);/*from w ww. j a v a 2s . com*/ HttpClient httpClient = httpClientProvider.get(); HttpResponse response = null; try { response = httpClient.execute(httpPost); int statusCode = response.getStatusLine().getStatusCode(); HttpEntity entity = response.getEntity(); if (statusCode != 200 || entity == null) { throw new IOException("invalid http response, status: " + statusCode + ", entity: " + ((entity != null) ? EntityUtils.toString(entity) : "none")); } return EntityUtils.toString(entity); } finally { HttpClientUtils.releaseConnection(response); } }
From source file:com.fanmei.pay4j.http.DefaultRequestExecutor.java
@Override public FanmeiResponse post(String url, String body, Charset charset) throws RequestException { HttpPost httpPost = new HttpPost(url); try {//from w ww .j a va 2 s. c o m httpPost.setEntity(new StringEntity(body, ContentType.create(URLEncodedUtils.CONTENT_TYPE, charset))); CloseableHttpResponse response = httpClient.execute(httpPost); return genFanmeiResponse(charset, response); } catch (Exception e) { throw RequestException.of(e); } }
From source file:com.kkbox.toolkit.internal.api.APIRequest.java
public void addFilePostParam(String path) { fileEntity = new FileEntity(new File(path), URLEncodedUtils.CONTENT_TYPE + HTTP.CHARSET_PARAM + HTTP.UTF_8); }
From source file:io.coala.capability.online.FluentHCOnlineCapability.java
public static HttpEntity toFormEntity(final List<NameValuePair> paramList) { final ContentType contentType = ContentType.create(URLEncodedUtils.CONTENT_TYPE, Consts.ISO_8859_1); final Charset charset = contentType != null ? contentType.getCharset() : null; final String s = URLEncodedUtils.format(paramList, charset != null ? charset.name() : null); byte[] raw;// w w w. j a v a 2s . c o m try { raw = charset != null ? s.getBytes(charset.name()) : s.getBytes(); } catch (UnsupportedEncodingException ex) { raw = s.getBytes(); } return new ApacheInternalByteArrayEntity(raw, contentType); }