从服务器获取图像

时间:2010-08-09 12:59:53

标签: android web-services soap

以下是我将代码从服务器位置提取到网络服务文件夹"web content"的代码。

// imports removed

public class WebService {

    public int writeToFileImage(int a) throws IOException{

        File file =new File("sdcard/myImage.jpg");
        file.createNewFile();

        URL u = new URL("http://172.29.26.40:8080/ExampleService/demo.jpg"); 
        URLConnection uc = u.openConnection(); 
        uc.connect(); 
        InputStream in = uc.getInputStream(); 
        FileOutputStream out;
        out = new FileOutputStream(file);
        final int BUF_SIZE = 1 << 8; 
        byte[] buffer = new byte[BUF_SIZE]; 
        int bytesRead = -1; 
        while((bytesRead = in.read(buffer)) > -1) { 
            out.write(buffer, 0, bytesRead); 
        } 
        in.close();
        out.close(); 
        return a;
    }
}

但我得到一个例外:

SOAP Response Envelope
- <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <soapenv:Body>
- <soapenv:Fault>
  <faultcode>soapenv:Server.userException</faultcode> 
  <faultstring>java.net.ConnectException: Connection timed out: connect</faultstring> 
- <detail>
  <ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">01HW040207</ns1:hostname> 
  </detail>
  </soapenv:Fault>
  </soapenv:Body>
  </soapenv:Envelope>

可能是错误的原因是什么?

1 个答案:

答案 0 :(得分:0)

我知道这篇文章很老了但是 github上有一个很棒的图片下载程序库

Android Image Loder

它完美无缺,它还包括缓存(你也可以关闭)多任务下载等等。

欢呼声 希望这会有所帮助...