从服务器获取图像
问题描述:
这里是我的代码从服务器位置获取图像到一个web服务文件夹"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>
可能是什么错误的原因是什么?
答
我知道这个职位是很老,但 有一个在github上一个伟大的形象下载库
它完美的作品,也是它包括高速缓存(在这里你也可以关闭),多任务下载等
欢呼 希望这有助于...
你尝试使用Web浏览器访问此网址是什么?也许资源根本不可用?因为我无法从这里得到它...... – Sephy 2010-08-09 13:07:13
希望你在描述中清楚你想要做什么。从你的代码看起来你想从服务器上将图像提取到设备的SD卡中。通常你不会公开8080端口。但请确保它可以从您的模拟器访问。术语SOAP,WebService应该与将图像下载到设备这一简单任务无关。 – dipu 2010-08-09 19:41:46