Java Code Examples for org.apache.http.protocol.HTTP#UTF_8

The following examples show how to use org.apache.http.protocol.HTTP#UTF_8 . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChatService.java    From barterli_android with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceiveMessage(final byte[] message) {

    String text = "";
    try {
        text = new String(message, HTTP.UTF_8);
        Logger.d(TAG, "Received:" + text);

        final ChatProcessTask chatProcessTask = mChatProcessTaskBuilder
                .setProcessType(ChatProcessTask.PROCESS_RECEIVE)
                .setMessage(text)
                .setChatDateFormatter(mChatDateFormatter)
                .setMessageDateFormatter(mMessageDateFormatter)
                .build();
        mChatProcessTaskBuilder.reset();
        mChatProcessor.submit(chatProcessTask);

    } catch (final UnsupportedEncodingException e) {
        e.printStackTrace();
        //Shouldn't be happening
    }

}
 
Example 2
Source File: HttpHeaderParser.java    From volley with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the charset specified in the Content-Type of this header,
 * or the HTTP default (UTF_8) if none can be found.
 */
public static String parseCharset(Map<String, String> headers) {
    String contentType = headers.get(HTTP.CONTENT_TYPE);
    if (contentType != null) {
        String[] params = contentType.split(";");
        for (int i = 1; i < params.length; i++) {
            String[] pair = params[i].trim().split("=");
            if (pair.length == 2) {
                if (pair[0].equals("charset")) {
                    return pair[1];
                }
            }
        }
    }

    return HTTP.UTF_8;
}
 
Example 3
Source File: RWEHTTPClient.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String execute(String hostname, String clientId, String request, String command)
        throws IOException, RWESmarthomeSessionExpiredException {
    // prepare connection
    HttpClient httpclient = httpHelper.getNewHttpClient();
    HttpPost httpPost = new HttpPost("https://" + hostname + command);
    httpPost.addHeader("ClientId", clientId);
    httpPost.addHeader("Connection", "Keep-Alive");
    HttpResponse response;
    StringEntity se = new StringEntity(request, HTTP.UTF_8);
    se.setContentType("text/xml");
    httpPost.setEntity(se);

    // execute HTTP request
    logger.trace("executing request: " + httpPost.getURI().toString());
    logger.trace("REQ:" + request);
    response = httpclient.execute(httpPost);
    logger.trace("Response: " + response.toString());

    // handle expired session
    if (response.getStatusLine().getStatusCode() == 401) {
        logger.info("401 Unauthorized returned - Session expired!");
        throw new RWESmarthomeSessionExpiredException("401 Unauthorized returned - Session expired!");
    }

    // handle return
    HttpEntity entity1 = response.getEntity();
    InputStream in = entity1.getContent();
    return InputStream2String.copyFromInputStream(in, "UTF-8");
}
 
Example 4
Source File: NetworkHelper.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
public static PostResult httpPost(String url, ArrayList<NameValuePair> pairs) {
	PostResult postResult = new PostResult();
	if(pairs == null || pairs.size() == 0){
		postResult.setSuccess(false);
		postResult.setResponseMsg("post date of the request params is null !");
		return postResult;
	}
	
	try {			
		HttpPost httppost = new HttpPost(url);
		httppost.addHeader("charset", HTTP.UTF_8);
		httppost.setHeader("Accept", "application/json,text/x-json,application/jsonrequest,text/json");	
		
		HttpEntity entity = new UrlEncodedFormEntity(pairs, HTTP.UTF_8);
		httppost.setEntity(entity);

		HttpClient httpclient = new DefaultHttpClient();
		httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 5000);
		httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 5000);
		HttpResponse response = httpclient.execute(httppost);
		int status = response.getStatusLine().getStatusCode();

		String resString = EntityUtils.toString(response.getEntity());
		postResult = parse(status, resString);
	} catch (Exception e) {
		Ln.i("NetworkHelper", "=== post Ln ===", e);
	} 
	
	return postResult;
}
 
Example 5
Source File: LruDiskCache.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the value at {@code index} to {@code value}.
 */
public void set(int index, String value) throws IOException {
    Writer writer = null;
    try {
        writer = new OutputStreamWriter(newOutputStream(index), HTTP.UTF_8);
        writer.write(value);
    } finally {
        IOUtils.closeQuietly(writer);
    }
}
 
Example 6
Source File: LruDiskCache.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the value at {@code index} to {@code value}.
 */
public void set(int index, String value) throws IOException {
    Writer writer = null;
    try {
        writer = new OutputStreamWriter(newOutputStream(index), HTTP.UTF_8);
        writer.write(value);
    } finally {
        IOUtils.closeQuietly(writer);
    }
}
 
Example 7
Source File: RequestParams.java    From sealtalk-android with MIT License 5 votes vote down vote up
public HttpEntity createFormEntity() {
    try {
        return new UrlEncodedFormEntity(getParamsList(), HTTP.UTF_8);
    } catch (UnsupportedEncodingException e) {
        return null; // Actually cannot happen when using utf-8
    }
}
 
Example 8
Source File: RestClient.java    From vocefiscal-android with Apache License 2.0 5 votes vote down vote up
public void setEntity(String entityContent) 
{
	try 
	{
		this.entity = new StringEntity(entityContent, HTTP.UTF_8);
	} catch (UnsupportedEncodingException e)
	{

	}

}
 
Example 9
Source File: BitherErrorApi.java    From bitherj with Apache License 2.0 5 votes vote down vote up
@Override
public HttpEntity getHttpEntity() throws Exception {
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    if (!Utils.isEmpty(this.mErrorMsg)) {
        params.add(new BasicNameValuePair(ERROR_MSG, this.mErrorMsg.trim()));
    }
    return new UrlEncodedFormEntity(params, HTTP.UTF_8);
}
 
Example 10
Source File: GetCookieApi.java    From bitherj with Apache License 2.0 5 votes vote down vote up
@Override
public HttpEntity getHttpEntity() throws Exception {
    long time = System.currentTimeMillis();
    time = time / 1000 * 1000 + 215;
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair(TIME_STRING, Long.toString(time)));
    return new UrlEncodedFormEntity(params, HTTP.UTF_8);

}
 
Example 11
Source File: SimpleMultipartEntity.java    From Android-Basics-Codes with Artistic License 2.0 4 votes vote down vote up
public void addPartWithCharset(String key, String value, String charset) {
    if (charset == null) charset = HTTP.UTF_8;
    addPart(key, value, "text/plain; charset=" + charset);
}
 
Example 12
Source File: ResponseStream.java    From android-open-project-demo with Apache License 2.0 4 votes vote down vote up
public ResponseStream(HttpResponse baseResponse, String requestUrl, long expiry) throws IOException {
    this(baseResponse, HTTP.UTF_8, requestUrl, expiry);
}
 
Example 13
Source File: SimpleMultipartEntity.java    From Mobike with Apache License 2.0 4 votes vote down vote up
public void addPartWithCharset(String key, String value, String charset) {
    if (charset == null) charset = HTTP.UTF_8;
    addPart(key, value, "text/plain; charset=" + charset);
}
 
Example 14
Source File: SimpleMultipartEntity.java    From Android-Basics-Codes with Artistic License 2.0 4 votes vote down vote up
public void addPartWithCharset(String key, String value, String charset) {
    if (charset == null) charset = HTTP.UTF_8;
    addPart(key, value, "text/plain; charset=" + charset);
}
 
Example 15
Source File: SimpleMultipartEntity.java    From Android-Basics-Codes with Artistic License 2.0 4 votes vote down vote up
public void addPartWithCharset(String key, String value, String charset) {
    if (charset == null) charset = HTTP.UTF_8;
    addPart(key, value, "text/plain; charset=" + charset);
}
 
Example 16
Source File: SimpleMultipartEntity.java    From android-project-wo2b with Apache License 2.0 4 votes vote down vote up
public void addPartWithCharset(String key, String value, String charset) {
    if (charset == null) charset = HTTP.UTF_8;
    addPart(key, value, "text/plain; charset=" + charset);
}
 
Example 17
Source File: ResponseStream.java    From BigApp_Discuz_Android with Apache License 2.0 4 votes vote down vote up
public ResponseStream(HttpResponse baseResponse, String requestUrl, long expiry) throws IOException {
    this(baseResponse, HTTP.UTF_8, requestUrl, expiry);
}
 
Example 18
Source File: SimpleMultipartEntity.java    From RestVolley with Apache License 2.0 4 votes vote down vote up
public void addPartWithCharset(String key, String value, String charset) {
    if (charset == null) {
        charset = HTTP.UTF_8;
    }
    addPart(key, value, "text/plain; charset=" + charset);
}