Search in sources :

Example 1 with HttpResponse

use of ch.boye.httpclientandroidlib.HttpResponse in project samourai-wallet-android by Samourai-Wallet.

the class WebUtil method tor_getURL.

private String tor_getURL(String URL) throws Exception {
    StrongHttpsClient httpclient = new StrongHttpsClient(context, R.raw.debiancacerts);
    httpclient.useProxy(true, strProxyType, strProxyIP, proxyPort);
    HttpGet httpget = new HttpGet(URL);
    HttpResponse response = httpclient.execute(httpget);
    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", "GET result via Tor:" + result);
    int idx = result.indexOf("{");
    if (idx != -1) {
        return result.substring(idx);
    } else {
        return result;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) HttpGet(ch.boye.httpclientandroidlib.client.methods.HttpGet) BufferedReader(java.io.BufferedReader) HttpResponse(ch.boye.httpclientandroidlib.HttpResponse) StrongHttpsClient(info.guardianproject.netcipher.client.StrongHttpsClient)

Example 2 with HttpResponse

use of ch.boye.httpclientandroidlib.HttpResponse 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 3 with HttpResponse

use of ch.boye.httpclientandroidlib.HttpResponse in project storymaker by StoryMaker.

the class StorymakerDownloadManager method downloadFromLigerServer.

private void downloadFromLigerServer() {
    String ligerUrl = indexItem.getExpansionFileUrl();
    String ligerPath = StorymakerIndexManager.buildFilePath(indexItem, context);
    String ligerObb = fileName;
    Timber.d("DOWNLOADING " + ligerObb + " FROM " + ligerUrl + " TO " + ligerPath);
    try {
        URI expansionFileUri = null;
        HttpGet request = null;
        HttpResponse response = null;
        File targetFolder = new File(ligerPath);
        String nameFilter = "";
        if (ligerObb.contains(indexItem.getExpansionFileVersion())) {
            nameFilter = fileName.replace(indexItem.getExpansionFileVersion(), "*") + "*.tmp";
        } else {
            nameFilter = fileName + "*.tmp";
        }
        Timber.d("CLEANUP: DELETING " + nameFilter + " FROM " + targetFolder.getPath());
        WildcardFileFilter oldFileFilter = new WildcardFileFilter(nameFilter);
        for (File oldFile : FileUtils.listFiles(targetFolder, oldFileFilter, null)) {
            Timber.d("CLEANUP: FOUND " + oldFile.getPath() + ", DELETING");
            FileUtils.deleteQuietly(oldFile);
        }
        // additional cleanup of pre-name-change files
        if (fileName.contains(scal.io.liger.Constants.MAIN)) {
            nameFilter = fileName.replace(scal.io.liger.Constants.MAIN + ".", "").replace(indexItem.getExpansionFileVersion(), "*");
            Timber.d("CLEANUP: DELETING OLD FILES " + nameFilter + " FROM " + targetFolder.getPath());
            oldFileFilter = new WildcardFileFilter(nameFilter);
            for (File oldFile : FileUtils.listFiles(targetFolder, oldFileFilter, null)) {
                Timber.d("CLEANUP: FOUND OLD FILE " + oldFile.getPath() + ", DELETING");
                FileUtils.deleteQuietly(oldFile);
            }
        }
        File targetFile = new File(targetFolder, ligerObb + ".tmp");
        // if there is no connectivity, do not queue item (no longer seems to pause if connection is unavailable)
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo ni = cm.getActiveNetworkInfo();
        if ((ni != null) && (ni.isConnectedOrConnecting())) {
            if (context instanceof Activity) {
                // FIXME move to strings
                Utils.toastOnUiThread((Activity) context, "Starting download of " + indexItem.getTitle() + ".", false);
            }
            // check preferences.  will also need to check whether tor is active within method
            SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
            boolean useTor = settings.getBoolean("pusetor", false);
            boolean useManager = settings.getBoolean("pusedownloadmanager", false);
            // if (checkTor(useTor, context)) {
            if (useTor && useManager) {
                Timber.e("ANDROID DOWNLOAD MANAGER IS NOT COMPATABLE WITH TOR");
                if (context instanceof Activity) {
                    // FIXME move to strings
                    Utils.toastOnUiThread((Activity) context, "Check settings, can't use download manager and tor", true);
                }
                StorymakerQueueManager.checkQueueFinished(context, targetFile.getName());
            } else if (useTor || !useManager) {
                downloadWithTor(useTor, Uri.parse(ligerUrl + ligerObb), mAppTitle + " content download", ligerObb, targetFile);
            } else {
                downloadWithManager(Uri.parse(ligerUrl + ligerObb), mAppTitle + " content download", ligerObb, Uri.fromFile(targetFile));
            }
        } else {
            Timber.d("NO CONNECTION, NOT QUEUEING DOWNLOAD: " + ligerUrl + ligerObb + " -> " + targetFile.getPath());
            if (context instanceof Activity) {
                // FIXME move to strings
                Utils.toastOnUiThread((Activity) context, "Check settings, no connection, can't start download", true);
            }
            StorymakerQueueManager.checkQueueFinished(context, targetFile.getName());
        }
    } catch (Exception e) {
        Timber.e(e, "DOWNLOAD ERROR: " + ligerUrl + ligerObb + " -> " + e.getMessage());
    }
}
Also used : NetworkInfo(android.net.NetworkInfo) SharedPreferences(android.content.SharedPreferences) ConnectivityManager(android.net.ConnectivityManager) HttpGet(ch.boye.httpclientandroidlib.client.methods.HttpGet) HttpResponse(ch.boye.httpclientandroidlib.HttpResponse) Activity(android.app.Activity) URI(java.net.URI) File(java.io.File) WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) ConnectTimeoutException(ch.boye.httpclientandroidlib.conn.ConnectTimeoutException)

Example 4 with HttpResponse

use of ch.boye.httpclientandroidlib.HttpResponse in project samourai-wallet-android by Samourai-Wallet.

the class WebUtil method tor_deleteURL.

public String tor_deleteURL(String URL, HashMap<String, String> args) throws Exception {
    StrongHttpsClient httpclient = new StrongHttpsClient(context, R.raw.debiancacerts);
    httpclient.useProxy(true, strProxyType, strProxyIP, proxyPort);
    HttpDelete httpdelete = new HttpDelete(new URI(URL));
    httpdelete.setHeader("Content-Type", "application/x-www-form-urlencoded");
    httpdelete.setHeader("charset", "utf-8");
    httpdelete.setHeader("Accept", "application/json");
    httpdelete.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)));
        }
    // httpdelete.setEntity(new UrlEncodedFormEntity(urlParameters));
    }
    HttpResponse response = httpclient.execute(httpdelete);
    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 : NameValuePair(ch.boye.httpclientandroidlib.NameValuePair) BasicNameValuePair(ch.boye.httpclientandroidlib.message.BasicNameValuePair) HttpDelete(ch.boye.httpclientandroidlib.client.methods.HttpDelete) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) HttpResponse(ch.boye.httpclientandroidlib.HttpResponse) StrongHttpsClient(info.guardianproject.netcipher.client.StrongHttpsClient) URI(java.net.URI) BasicNameValuePair(ch.boye.httpclientandroidlib.message.BasicNameValuePair) BufferedReader(java.io.BufferedReader)

Example 5 with HttpResponse

use of ch.boye.httpclientandroidlib.HttpResponse 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)5 StrongHttpsClient (info.guardianproject.netcipher.client.StrongHttpsClient)4 BufferedReader (java.io.BufferedReader)4 InputStream (java.io.InputStream)4 InputStreamReader (java.io.InputStreamReader)4 URI (java.net.URI)4 NameValuePair (ch.boye.httpclientandroidlib.NameValuePair)3 BasicNameValuePair (ch.boye.httpclientandroidlib.message.BasicNameValuePair)3 ArrayList (java.util.ArrayList)3 UrlEncodedFormEntity (ch.boye.httpclientandroidlib.client.entity.UrlEncodedFormEntity)2 HttpGet (ch.boye.httpclientandroidlib.client.methods.HttpGet)2 HttpPost (ch.boye.httpclientandroidlib.client.methods.HttpPost)2 Activity (android.app.Activity)1 SharedPreferences (android.content.SharedPreferences)1 ConnectivityManager (android.net.ConnectivityManager)1 NetworkInfo (android.net.NetworkInfo)1 HttpDelete (ch.boye.httpclientandroidlib.client.methods.HttpDelete)1 ConnectTimeoutException (ch.boye.httpclientandroidlib.conn.ConnectTimeoutException)1 File (java.io.File)1 IOException (java.io.IOException)1