Wget or similar for Android

18,251

Using wget or ndk for that is a bad idea : go directly java and use HttpClient to craft a post request : example can be found here.

The response will contain your data, ready to be saved to a file.

Additionally, you can put it in an asynch task, progress monitoring : forking an external process like Curl ou wget should be kept as last chance (that communicating with a server is clearly not)

Share:
18,251
jbc25
Author by

jbc25

Android developer

Updated on June 27, 2022

Comments

  • jbc25
    jbc25 almost 2 years

    I need to make petitions against a https server and download data that the server sends back (text, video files or image files), inside my Android app.

    It works fine in the terminal of suse Linux and wget or curl. Request have this structure:

    wget --post-data "token=xxxx&option1=1&option2=4&File=video" https://api.serverx.com/ --no-check-certificate
    

    My question is if there is any wget or similar working in Android, or how can I make this kind of petitions in another way.

    I read about implement wget in the NDK but I'd like to know your experience or recomendations. Thanks

    Solution

    Using NDK to port Wget was too complicated. After some research I found a solution using DefaultHttpClient and adding a couple of classes to avoid checking the certificates. I follow this article

    SchemeRegistry schemeRegistry = new SchemeRegistry();
        schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443));
    
        HttpParams params = new BasicHttpParams();
        params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30);
        params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30));
        params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    
        ClientConnectionManager cm = new SingleClientConnManager(params, schemeRegistry);
        DefaultHttpClient httpClient = new DefaultHttpClient(cm, params);
    
  • jbc25
    jbc25 almost 12 years
    I will have a look to this solution. Also I try with HttpsURLConnection