Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

web services - Android: File listing of web server

I am trying to retrieve file listing from my (apache) http server via an android phone. Searched the web and forum without success. I was however able to do this in standard java using:

package at.klp.serverlist;

import java.net.URL;
import java.util.List;
import org.apache.ivy.util.url.ApacheURLLister;

public class ServerFileListJava {

    public static void main(String[] args) {

        URL url1;
        List serverDir;

        try {           
            url1 = new URL("http://...url to server...");           
            ApacheURLLister lister1 = new ApacheURLLister();         
            serverDir = lister1.listAll(url1);
            System.out.println(serverDir);         
        } 

        catch (Exception e) {
            e.printStackTrace();
        }               

    }//end main
}//end class

Is a similar class available in Android, or can file listing somehow be done using org.apache.http*? I do not really want to use a WebView, or separate the html code using HttpGet and HttpResponse.

Thanks a lot for helping, any ideas?

Solved thanks to your answers. I imported ivy-2.0.0-rc1.jar into my project, did not know that this works! This video demonstrates how to import .jar`s into an Android project: http://www.youtube.com/watch?v=eY_uqi_qIz0&noredirect=1 thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

ApacheURLLister is a pretty simple class with no special dependencies. You should have no problems copying it and use it directly in your code: https://svn.apache.org/repos/asf/ant/ivy/core/trunk/src/java/org/apache/ivy/util/url/ApacheURLLister.java


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...