Download a file with DefaultHTTPClient and preemptive authentication

后端 未结 1 1008
后悔当初
后悔当初 2021-01-02 20:39

After I had a lot of problems with preemptive authentication , I got it finally working. Now the next problem. I want to get a file with it, but I don\'t know how. I thought

相关标签:
1条回答
  • 2021-01-02 21:11

    Well, I solved it myself now - here the solution:

            StringBuffer tmp = new StringBuffer();  // for content
    
            if (entity != null) {
                InputStream is = entity.getContent();
    
                int l = 0;
                byte[] t = new byte[1024];
    
                while ((l = is.read(t)) != -1) {
                    for (int i=0; i<l ; i++){
                        tmp.append((char)t[i]);
                    }
                }
            }
    
            return tmp.toString(); 
    
    0 讨论(0)
提交回复
热议问题