访问自己的阿里云服务器挂的servlet:
package com.michael.cloudphotos; import android.os.Message; import android.util.Log; import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.DataInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import android.os.Handler; public class gethttp extends Thread { public String m_url; public Handler handler; public gethttp(String url, Handler handler) { this.m_url=url; this.handler=handler; } @Override public void run() { HttpURLConnection connection=null; try { URL url=new URL(m_url); connection=(HttpURLConnection) url.openConnection(); connection.connect(); String lines=null; // BufferedReader br=new BufferedReader(new InputStreamReader(connection.getInputStream())); DataInputStream ios=new DataInputStream(new DataInputStream(connection.getInputStream())); lines=ios.readUTF(); Log.i("info:",lines); Message msg=new Message(); msg.what=1; msg.obj=lines; handler.sendMessage(msg); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }finally { if(connection!=null) { connection.disconnect(); } } } }