Proxy proxy = new Proxy(java.net.Proxy.Type.HTTP, new InetSocketAddress("10.0.0.172",80)); URL url = new URL(urlStr); HttpURLConnection conn=(HttpURLConnection) url.openConnection(proxy);
if (conn == null){ throw new IOException("URLConnection instance is null"); }
找下资料吧,网上很多的。
连接方式有很多种,socket, 或者使用android自带的Httpclient或者HttpConnection
各种传输方式,返回值如何获取,网上都是一大堆一大堆的。
// String urlStr = "http://tv.ruyi.com/portal";
String urlStr = "http://XX.XX.XX.XX:XXXX/live/index.jsp";
Proxy proxy = new Proxy(java.net.Proxy.Type.HTTP, new InetSocketAddress("10.0.0.172",80));
URL url = new URL(urlStr);
HttpURLConnection conn=(HttpURLConnection) url.openConnection(proxy);
if (conn == null){
throw new IOException("URLConnection instance is null");
}
conn.setConnectTimeout(30000);//
conn.setDoOutput(true); // 发送POST请求必须设置允许输出,表示允许对外输出
conn.setUseCaches(false); // 不使用Cache
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "*/*");
conn.setRequestProperty("Connection", "Keep-Alive");// 维持长连接
conn.setRequestProperty("Charset", "UTF-8");
conn.setRequestProperty("Content-Type", "text/xml; charset=UTF-8");
int responseCode = conn.getResponseCode();
Log.e("IndexActivity","responseCode is:"+responseCode);
if(responseCode == 200){
InputStream stream = conn.getInputStream();
result = inStream2String(stream);
String temvit = result;
Log.e("error","result" + result);
if (temvit.substring(0, 3).trim().equals("861")||temvit.substring(0, 3).trim()=="861") {//此处视情况而定
result = temvit.substring(2, 13);
}
if (temvit.substring(0, 1).trim().equals("1")||temvit.substring(0, 1).trim()=="1") {//此处也是,视情况修改
result = temvit;
}
;
}else{
}
我也是copy的,就是那个result吧