Example usage for org.apache.http.protocol HTTP UTF_8

List of usage examples for org.apache.http.protocol HTTP UTF_8

Introduction

In this page you can find the example usage for org.apache.http.protocol HTTP UTF_8.

Prototype

String UTF_8

To view the source code for org.apache.http.protocol HTTP UTF_8.

Click Source Link

Usage

From source file:com.ncu.sdroidagent.ServerUtilities.java

/**
 * Issue a POST request to the SDroid server.
 *
 * @param endpoint//from  www  .ja  v  a 2s  . c  o m
 *            POST address.
 * @param params
 *            request parameters.
 *
 * @throws IOException
 *             propagated from POST.
 */
private static void post(String endpoint, Map<String, String> params) throws IOException {

    String result = null;

    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(endpoint);

    List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>();
    Iterator<Entry<String, String>> iterator = params.entrySet().iterator();

    while (iterator.hasNext()) {
        Entry<String, String> param = iterator.next();
        nameValuePair.add(new BasicNameValuePair(param.getKey(), param.getValue()));
    }

    try {
        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair, HTTP.UTF_8));
    } catch (UnsupportedEncodingException ex) {
        ex.printStackTrace();
    }

    try {
        HttpResponse response = httpClient.execute(httpPost);
        if (response.getStatusLine().getStatusCode() == 200) {
            result = EntityUtils.toString(response.getEntity());
        } else {
            result = "HttpPost False!";
        }
        Log.d("ServerUtilities", "result: " + result);

    } catch (ClientProtocolException cpe) {
        cpe.printStackTrace();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
}

From source file:com.phonty.improved.Login.java

public boolean process() {
    StringBuilder builder = new StringBuilder();
    final String cookieName = "sessionid";
    httppost = new HttpPost(APIURL);

    try {/*from ww  w  . jav a  2  s. c o m*/
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("username", login));
        nvps.add(new BasicNameValuePair("password", password));

        httppost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
        HttpResponse response = client.execute(httppost);

        StatusLine statusLine = response.getStatusLine();
        int statusCode = statusLine.getStatusCode();

        if (statusCode == 200) {
            List<Cookie> cookies = client.getCookieStore().getCookies();
            if (cookies.isEmpty()) {
            } else {
                for (int i = 0; i < cookies.size(); i++) {
                    if (cookieName.equals(cookies.get(i).getName())) {
                        // We get the session id. That what auth is.
                        SESSION_COOKIE = cookies.get(i);
                        SESSION_ID = cookies.get(i).getValue();
                    }
                }
            }

            HttpEntity entity = response.getEntity();
            InputStream content = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(content));
            String line;
            while ((line = reader.readLine()) != null) {
                builder.append(line);
                this.VALUE = line;
            }
        } else {
            this.VALUE = "0.0";
        }

    } catch (ClientProtocolException e) {
        e.printStackTrace();
        return false;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }

    if (this.VALUE.equals("AUTH_OK")) {
        return true;
    } else {
        logout();
        return false;
    }
}

From source file:li.barter.http.BlRequest.java

@Override
protected VolleyError parseNetworkError(final VolleyError volleyError) {

    if (volleyError.errorCode == ErrorCode.BAD_REQUEST_ERROR) {
        try {/*from w w  w  . j  a v a2s  . com*/

            final HttpResponseParser parser = new HttpResponseParser();
            return parser.getErrorResponse(mRequestId,
                    new String(volleyError.networkResponse.data, HTTP.UTF_8));
        } catch (final UnsupportedEncodingException e) {
            return new ParseError(e);
        } catch (final JSONException e) {
            return new ParseError(e);
        }
    } else {
        if (volleyError.networkResponse != null && volleyError.networkResponse.data != null) {
            try {
                Logger.w(TAG, "Error message %s", new String(volleyError.networkResponse.data, HTTP.UTF_8));
            } catch (UnsupportedEncodingException e) {
                //Not important since the error message is being printed for dev info only
            }
        }
        return super.parseNetworkError(volleyError);
    }
}

From source file:anhttpclient.impl.request.HttpPostWebRequest.java

/**
 * {@inheritDoc}//from  w  w  w. j  av a  2 s .com
 */
public void addFormParam(String name, String value, String charset) {
    parts.clear();
    formParamsCharset = charset != null ? charset : HTTP.UTF_8;
    formParams.put(name, value);
}

From source file:com.coodesoft.notee.NoteeNetworkReply.java

public boolean login(String strName, String strPwd) {
    String strAction = "login";

    // http/*from   w  w w  . j a  v a2  s  .com*/
    HttpPost httpPost = new HttpPost(m_strNoteeUrlBase + strAction);
    httpPost.addHeader("Connection", "Keep-Alive");

    // post parameter
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("name", strName));
    params.add(new BasicNameValuePair("pwd", strPwd));
    params.add(new BasicNameValuePair("login_from", m_strLoginFrom));
    // character set
    HttpEntity entity;
    try {
        entity = new UrlEncodedFormEntity(params, HTTP.UTF_8);
        httpPost.setEntity(entity);
    } catch (UnsupportedEncodingException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
        return false;
    }

    try {
        HttpResponse response = m_httpClient.execute(httpPost);

        if (parseResponse(response))
            return true;

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return false;
}

From source file:com.android.volley.util.HttpHeaderParser.java

/**
 * Returns the charset specified in the Content-Type of this header,
 * or the HTTP default (ISO-8859-1) if none can be found.
 *//*from   w  w w .j a  va 2s  . co  m*/
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; // 20131109 Nevin modify to make UTF-8 the default encoding
}

From source file:Main.java

/**
 * Encode/escape www-url-form-encoded content.
 * <p/>/*from  w  ww  . j  av a2s. c  om*/
 * Uses the {@link #URLENCODER} set of characters, rather than
 * the set; this is for compatibilty with previous
 * releases, URLEncoder.encode() and most browsers.
 *
 * @param content the content to encode, will convert space to '+'
 * @param charset the charset to use
 * @return encoded string
 */
private static String encodeFormFields(final String content, final Charset charset) {
    if (content == null) {
        return null;
    }
    return urlencode(content, charset != null ? charset : Charset.forName(HTTP.UTF_8), URLENCODER, true);
}

From source file:com.supremainc.biostar2.sdk.volley.toolbox.HttpHeaderParser.java

/**
 * Returns the charset specified in the Content-Type of this header,
 * or the HTTP default (ISO-8859-1) if none can be found.
 *//*from   ww w . ja v a  2s.c  o  m*/
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;
    //       return HTTP.DEFAULT_CONTENT_CHARSET;
}

From source file:geotag.core.HttpHelper.java

public Boolean POSTRequest(List<NameValuePair> geoTagData) {
    try {/*  ww  w . j  a  va2s .  c  o m*/
        clientPostRequest.setEntity(new UrlEncodedFormEntity(geoTagData, HTTP.UTF_8));

        checkForRequestError(clientPostRequest);

        return true;
    } catch (Exception e) {
        return false;
    }
}

From source file:com.sixsq.slipstream.DeploymentController.java

public URI runModule(String module) throws MojoExecutionException {

    try {//from   w ww  .ja  va 2s.  c om
        URI postUri = relativeURI("run");

        HttpPost httppost = new HttpPost(postUri);

        List<NameValuePair> formInfo = new ArrayList<NameValuePair>();
        formInfo.add(new BasicNameValuePair("refqname", module));

        httppost.setEntity(new UrlEncodedFormEntity(formInfo, HTTP.UTF_8));

        HttpResponse response = client.execute(httppost);
        HttpEntity entity = response.getEntity();
        EntityUtils.consume(entity);

        Header location = response.getFirstHeader("location");
        if (location == null) {
            throw new MojoExecutionException("running module failed; no redirect given");
        }

        URI runUri = new URI(location.getValue());

        return runUri;

    } catch (IOException e) {
        throw new MojoExecutionException("IO exception when trying to contact server", e);
    } catch (URISyntaxException e) {
        throw new MojoExecutionException("invalid URI syntax", e);
    }
}