Search in sources :

Example 1 with UrlEncodedFormEntity

use of ch.boye.httpclientandroidlib.client.entity.UrlEncodedFormEntity in project samourai-wallet-android by Samourai-Wallet.

the class WebUtil method tor_postURL.

public String tor_postURL(String URL, HashMap<String, String> args) throws Exception {
    StrongHttpsClient httpclient = new StrongHttpsClient(context, R.raw.debiancacerts);
    httpclient.useProxy(true, strProxyType, strProxyIP, proxyPort);
    HttpPost httppost = new HttpPost(new URI(URL));
    httppost.setHeader("Content-Type", "application/x-www-form-urlencoded");
    httppost.setHeader("charset", "utf-8");
    httppost.setHeader("Accept", "application/json");
    httppost.setHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36");
    if (args != null) {
        List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
        for (String key : args.keySet()) {
            urlParameters.add(new BasicNameValuePair(key, args.get(key)));
        }
        httppost.setEntity(new UrlEncodedFormEntity(urlParameters));
    }
    HttpResponse response = httpclient.execute(httppost);
    StringBuffer sb = new StringBuffer();
    sb.append(response.getStatusLine()).append("\n\n");
    InputStream is = response.getEntity().getContent();
    BufferedReader br = new BufferedReader(new InputStreamReader(is));
    String line = null;
    while ((line = br.readLine()) != null) {
        sb.append(line);
    }
    httpclient.close();
    String result = sb.toString();
    // Log.d("WebUtil", "POST result via Tor:" + result);
    int idx = result.indexOf("{");
    if (idx != -1) {
        return result.substring(idx);
    } else {
        return result;
    }
}
Also used : HttpPost(ch.boye.httpclientandroidlib.client.methods.HttpPost) NameValuePair(ch.boye.httpclientandroidlib.NameValuePair) BasicNameValuePair(ch.boye.httpclientandroidlib.message.BasicNameValuePair) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) HttpResponse(ch.boye.httpclientandroidlib.HttpResponse) StrongHttpsClient(info.guardianproject.netcipher.client.StrongHttpsClient) UrlEncodedFormEntity(ch.boye.httpclientandroidlib.client.entity.UrlEncodedFormEntity) URI(java.net.URI) BasicNameValuePair(ch.boye.httpclientandroidlib.message.BasicNameValuePair) BufferedReader(java.io.BufferedReader)

Example 2 with UrlEncodedFormEntity

use of ch.boye.httpclientandroidlib.client.entity.UrlEncodedFormEntity in project samourai-wallet-android by Samourai-Wallet.

the class WebUtil method tor_postURL.

public String tor_postURL(String URL, HashMap<String, String> args) throws Exception {
    StrongHttpsClient httpclient = new StrongHttpsClient(context, R.raw.debiancacerts);
    httpclient.useProxy(true, strProxyType, strProxyIP, proxyPort);
    HttpPost httppost = new HttpPost(new URI(URL));
    httppost.setHeader("Content-Type", "application/x-www-form-urlencoded");
    httppost.setHeader("charset", "utf-8");
    httppost.setHeader("Accept", "application/json");
    httppost.setHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36");
    if (args != null) {
        List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
        for (String key : args.keySet()) {
            urlParameters.add(new BasicNameValuePair(key, args.get(key)));
        }
        httppost.setEntity(new UrlEncodedFormEntity(urlParameters));
    }
    HttpResponse response = httpclient.execute(httppost);
    StringBuffer sb = new StringBuffer();
    sb.append(response.getStatusLine()).append("\n\n");
    InputStream is = response.getEntity().getContent();
    BufferedReader br = new BufferedReader(new InputStreamReader(is));
    String line = null;
    while ((line = br.readLine()) != null) {
        sb.append(line);
    }
    httpclient.close();
    String result = sb.toString();
    // Log.d("WebUtil", "POST result via Tor:" + result);
    int idx = result.indexOf("{");
    if (idx != -1) {
        return result.substring(idx);
    } else {
        return result;
    }
}
Also used : HttpPost(ch.boye.httpclientandroidlib.client.methods.HttpPost) NameValuePair(ch.boye.httpclientandroidlib.NameValuePair) BasicNameValuePair(ch.boye.httpclientandroidlib.message.BasicNameValuePair) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) HttpResponse(ch.boye.httpclientandroidlib.HttpResponse) StrongHttpsClient(info.guardianproject.netcipher.client.StrongHttpsClient) UrlEncodedFormEntity(ch.boye.httpclientandroidlib.client.entity.UrlEncodedFormEntity) URI(java.net.URI) BasicNameValuePair(ch.boye.httpclientandroidlib.message.BasicNameValuePair) BufferedReader(java.io.BufferedReader)

Aggregations

HttpResponse (ch.boye.httpclientandroidlib.HttpResponse)2 NameValuePair (ch.boye.httpclientandroidlib.NameValuePair)2 UrlEncodedFormEntity (ch.boye.httpclientandroidlib.client.entity.UrlEncodedFormEntity)2 HttpPost (ch.boye.httpclientandroidlib.client.methods.HttpPost)2 BasicNameValuePair (ch.boye.httpclientandroidlib.message.BasicNameValuePair)2 StrongHttpsClient (info.guardianproject.netcipher.client.StrongHttpsClient)2 BufferedReader (java.io.BufferedReader)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2