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.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 ww .ja  va  2 s  . co 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:com.googlecode.sardine.impl.methods.HttpMkCol.java

public HttpMkCol(URI url) {
    this.setURI(url);
    this.setHeader("Content-Type", "text/xml" + HTTP.CHARSET_PARAM + HTTP.UTF_8.toLowerCase());
}

From source file:pingdesktop.Model.HttpHandler.java

public static String doPost(List<NameValuePair> nvps, String target_url) throws IOException {

    /* create the HTTP client and POST request */
    HttpPost httpPost = new HttpPost(BaseUrl + target_url);

    /* add some request parameters for a form request */
    //        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    ////w w w .j a  v a2s  .  c o  m
    //        nvps.add(new BasicNameValuePair("username", "pangeranweb"));
    //        nvps.add(new BasicNameValuePair("password", "anisnuzulan"));
    nvps.add(new BasicNameValuePair("Content-Type", "application/x-www-form-urlencoded"));
    httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

    /* execute request */
    HttpResponse httpResponse = httpClient.execute(httpPost);
    HttpEntity httpEntity = httpResponse.getEntity();

    /* process response */
    if (httpResponse.getStatusLine().getStatusCode() == 200) {
        String responseText = EntityUtils.toString(httpEntity);
        return responseText;
    } else {
        return "Invalid HTTP response: " + httpResponse.getStatusLine().getStatusCode();
    }

}

From source file:com.googlecode.sardine.impl.methods.HttpPropPatch.java

public HttpPropPatch(URI url) {
    this.setURI(url);
    this.setHeader("Content-Type", "text/xml" + HTTP.CHARSET_PARAM + HTTP.UTF_8.toLowerCase());
}

From source file:no.hig.gsd.quizgame.ServerUtilities.java

/**
 * Register this account/device pair within the server.
 *
 * @return whether the registration succeeded or not.
 */// w ww .j av a  2  s .  co m
public static String register(final Context context, final String regId) {

    Log.i("remote", "registering device (regId = " + regId + ")");
    String usm = LoginActivity.usm;
    String retSrc = "";
    try {
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost("http://89.250.116.142/Quizgame/jaxrs/quizgame/gcm");
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("username", usm));
        nameValuePairs.add(new BasicNameValuePair("regId", regId));

        post.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));

        HttpResponse httpResponse = client.execute(post);
        HttpEntity entity = httpResponse.getEntity();
        retSrc = EntityUtils.toString(entity);
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (retSrc.equals("success")) {
        return status = "success";
    } else {

        return status = "failure";
    }

}

From source file:com.mondospider.android.lib.LibHTTP.java

public LibHTTP() {
    HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(httpParams, HTTP.UTF_8);
}

From source file:org.dataconservancy.archive.impl.fcrepo.ri.RIQueryResult.java

RIQueryResult(InputStream in) {
    try {//from  w  w w . j a  va  2 s.  co  m
        reader = new BufferedReader(new InputStreamReader(in, HTTP.UTF_8));
    } catch (UnsupportedEncodingException wontHappen) {
        throw new RuntimeException(wontHappen);
    }
    factory = new ValueFactoryImpl();
    exhausted = false;
}

From source file:com.pursuer.reader.easyrss.Utils.java

public static DefaultHttpClient createHttpClient() {
    final HttpParams config = new BasicHttpParams();
    HttpProtocolParams.setVersion(config, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(config, HTTP.UTF_8);
    HttpProtocolParams.setUserAgent(config, Utils.class.getName());

    final SchemeRegistry reg = new SchemeRegistry();
    reg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    reg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

    final ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(config, reg);

    final DefaultHttpClient client = new DefaultHttpClient(manager, config);
    client.getParams().setParameter("http.socket.timeout", 30 * 1000);
    return client;
}

From source file:com.dajodi.scandic.JSoupScraper.java

@Override
public Map<String, String> scrapeFormInputFields(InputStream inStream) {

    try {/*www.ja  va 2  s .  co  m*/
        Document doc = Jsoup.parse(inStream, HTTP.UTF_8, "");

        Element form = doc.body().getElementById("aspnetForm");

        Elements inputNodes = form.getElementsByTag("input");
        Map<String, String> inputMap = new HashMap<String, String>();

        for (Element element : inputNodes) {

            String name = element.attr("name");
            String value = element.attr("value");

            if (name != null) {
                inputMap.put(name, value == null ? "" : value);
            } else {
                //TODO: remove me
                Log.d("Something weird");
            }
        }

        doc.empty();
        return inputMap;
    } catch (Exception e) {
        throw new ScandicHtmlException(e);
    }
}

From source file:ti.modules.titanium.network.TiJsonBody.java

@Override
public String getCharset() {
    return HTTP.UTF_8;
}