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:amazonechoapi.AmazonEchoApi.java

public boolean httpLogin() {

    try {//ww  w. j  a va 2 s . c om
        String output = httpGet("");

        Document doc = Jsoup.parse(output);
        Elements forms = doc.select("form");
        String action = forms.attr("action");

        if (action.isEmpty()) {
            return false;
        }

        Elements hidden = doc.select("input[type=hidden]");
        List<NameValuePair> nvps = new ArrayList<>();
        nvps.add(new BasicNameValuePair("email", USERNAME));
        nvps.add(new BasicNameValuePair("password", PASSWORd));
        nvps.add(new BasicNameValuePair("create", "0"));

        for (Element el1 : hidden) {
            nvps.add(new BasicNameValuePair(el1.attr("name"), el1.attr("value")));
        }

        HttpPost httpPost = new HttpPost(action);
        httpPost.setHeader(HttpHeaders.USER_AGENT,
                "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13");
        httpPost.setHeader(HttpHeaders.REFERER, BASE_URL);
        httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

        HttpResponse httpResponse = httpclient.execute(httpPost);

        httpResponse.getEntity();
        HttpEntity entity = httpResponse.getEntity();
        if (entity != null) {
            EntityUtils.consume(entity);
        }
        System.out.println("Login successful");
        return true;

    } catch (Exception e) {
        System.out.println("Login Error:" + e.getMessage());
        return false;
    }
}

From source file:de.escidoc.core.test.aa.UserAccountTestBase.java

/**
 * Test activating an UserAccount./*from   ww  w  .j  a va  2 s.  c o  m*/
 *
 * @param id           The id of the UserAccount.
 * @param taskParamXml The task parameter in an XML structure.
 * @throws Exception If anything fails.
 */
protected String activate(final String id, final String taskParamXml) throws Exception {

    Object result = getUserAccountClient().activate(id, taskParamXml);
    String xmlResult = null;
    if (result instanceof HttpResponse) {
        HttpResponse method = (HttpResponse) result;
        xmlResult = EntityUtils.toString(method.getEntity(), HTTP.UTF_8);
        assertHttpStatusOfMethod("", method);
        if (xmlResult.equals("")) {
            xmlResult = null;
        }

    } else if (result instanceof String) {
        xmlResult = (String) result;
    }
    return xmlResult;
}

From source file:com.hiyjeain.android.DevBase.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 w  ww.j  a  v a 2  s  .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;
}

From source file:com.mockey.storage.xml.MockeyXmlFileManager.java

/**
 * /*from w  w  w. j a v a2s.c  om*/
 * @param file
 *            - xml configuration file for Mockey
 * @throws IOException
 * @throws SAXException
 * @throws SAXParseException
 */
private String getFileContentAsString(File file) throws IOException, SAXParseException, SAXException {

    FileInputStream fstream = new FileInputStream(file);
    BufferedReader br = new BufferedReader(new InputStreamReader(fstream, Charset.forName(HTTP.UTF_8)));
    StringBuffer inputString = new StringBuffer();
    // Read File Line By Line
    String strLine = null;
    while ((strLine = br.readLine()) != null) {
        // Print the content on the console
        inputString.append(new String(strLine.getBytes(HTTP.UTF_8)));
    }
    return inputString.toString();

}

From source file:com.pursuer.reader.easyrss.network.AbsDataSyncer.java

protected Reader httpGetQueryReader(final AbsURL url) throws DataSyncerException {
    try {/*from  ww w . j a v  a 2  s.  c om*/
        return new InputStreamReader(httpGetQueryStream(url), HTTP.UTF_8);
    } catch (final UnsupportedEncodingException e) {
        throw new DataSyncerException(e);
    }
}

From source file:sg.macbuntu.android.pushcontacts.SmsReceiver.java

private static void postData(String user, String phone, String sms, String sender) {

    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(PUSH_URL);

    try {//from w  w  w  . j  ava  2 s .c  o m
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
        nameValuePairs.add(new BasicNameValuePair("user", user));
        nameValuePairs.add(new BasicNameValuePair("sender", sender));
        nameValuePairs.add(new BasicNameValuePair("phone", phone));
        nameValuePairs.add(new BasicNameValuePair("sms", sms));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));

        // Execute HTTP Post Request
        httpclient.execute(httppost);

    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }
}

From source file:org.metasyntactic.utilities.ExceptionUtilities.java

/**
 * Look into the files folder to see if there are any "*.stacktrace" files. If
 * any are present, submit them to the trace server.
 *///ww  w  .j ava 2 s .  com
public static void submitStackTraces() {
    try {
        String[] list = searchForStackTraces();
        if (list != null && list.length > 0) {
            for (int i = 0; i < list.length; i++) {
                File file = new File(FilesPath, list[i]);
                String version = list[i].split("-")[0];
                StringBuilder contents = new StringBuilder();
                BufferedReader input = new BufferedReader(new FileReader(file));
                String line = null;
                while ((line = input.readLine()) != null) {
                    contents.append(line);
                    contents.append(System.getProperty("line.separator"));
                }
                input.close();
                String stacktrace;
                stacktrace = contents.toString();
                file.delete();

                DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpPost httpPost = new HttpPost(
                        "http://" + NowPlayingApplication.host + ".appspot.com/ReportCrash");
                List<NameValuePair> nvps = new ArrayList<NameValuePair>();
                nvps.add(new BasicNameValuePair("name", Package));
                nvps.add(new BasicNameValuePair("version", version));
                nvps.add(new BasicNameValuePair("trace", stacktrace));
                httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

                httpClient.execute(httpPost);
            }
        }
    } catch (Exception e) {
    } finally {
        String[] list = searchForStackTraces();
        for (int i = 0; i < list.length; i++) {
            File file = new File(FilesPath, list[i]);
            file.delete();
        }
    }
}

From source file:com.microsoft.live.TokenRequest.java

/**
 * Performs the Token Request and returns the OAuth server's response.
 *
 * @return The OAuthResponse from the server
 * @throws LiveAuthException if there is any exception while executing the request
 *                           (e.g., IOException, JSONException)
 *///from   ww w. ja v  a 2s  .  co  m
public OAuthResponse execute() throws LiveAuthException {
    final Uri requestUri = Config.INSTANCE.getOAuthTokenUri();

    final HttpPost request = new HttpPost(requestUri.toString());

    final List<NameValuePair> body = new ArrayList<NameValuePair>();
    body.add(new BasicNameValuePair(OAuth.CLIENT_ID, this.clientId));

    // constructBody allows subclasses to add to body
    this.constructBody(body);

    try {
        final UrlEncodedFormEntity entity = new UrlEncodedFormEntity(body, HTTP.UTF_8);
        entity.setContentType(CONTENT_TYPE);
        request.setEntity(entity);
    } catch (UnsupportedEncodingException e) {
        throw new LiveAuthException(ErrorMessages.CLIENT_ERROR, e);
    }

    final HttpResponse response;
    try {
        response = this.client.execute(request);
    } catch (ClientProtocolException e) {
        throw new LiveAuthException(ErrorMessages.SERVER_ERROR, e);
    } catch (IOException e) {
        throw new LiveAuthException(ErrorMessages.SERVER_ERROR, e);
    }

    final HttpEntity entity = response.getEntity();
    final String stringResponse;
    try {
        stringResponse = EntityUtils.toString(entity);
    } catch (IOException e) {
        throw new LiveAuthException(ErrorMessages.SERVER_ERROR, e);
    }

    final JSONObject jsonResponse;
    try {
        jsonResponse = new JSONObject(stringResponse);
    } catch (JSONException e) {
        throw new LiveAuthException(ErrorMessages.SERVER_ERROR, e);
    }

    if (OAuthErrorResponse.validOAuthErrorResponse(jsonResponse)) {
        return OAuthErrorResponse.createFromJson(jsonResponse);
    } else if (OAuthSuccessfulResponse.validOAuthSuccessfulResponse(jsonResponse)) {
        return OAuthSuccessfulResponse.createFromJson(jsonResponse);
    } else {
        throw new LiveAuthException(ErrorMessages.SERVER_ERROR);
    }
}

From source file:cn.com.loopj.android.http.SimpleMultipartEntity.java

public void addPartWithCharset(String key, String value, String charset) {
    if (charset == null)
        charset = HTTP.UTF_8;
    addPart(key, value, "text/plain; charset=" + charset);
}

From source file:com.jana.android.net.HttpPostConnection.java

private void updateParamsFromJson(HttpPost httpPost) {
    try {/*from ww  w  .j a  va2  s  .  c om*/

        StringEntity entity = new StringEntity(paramsFromJson, HTTP.UTF_8);
        //         entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE,
        //               "application/json"));
        httpPost.setEntity(entity);

    } catch (UnsupportedEncodingException e) {

        Logger.w("Failure while establishing url connection as unsupported encoding error > " + e.getMessage());

        e.printStackTrace();
    }
}