当前位置: 技术问答>java相关
谁能给一段java读取网页代码的例子。
来源: 互联网 发布时间:2015-10-31
本文导语: 就是通过网址,显示出这个网址的html的文件。 | try { String sProgram = "jxsj"; if(sType.equals("JXXM")){ sProgra...
就是通过网址,显示出这个网址的html的文件。
|
try
{
String sProgram = "jxsj";
if(sType.equals("JXXM")){
sProgram = "jxxm";
int iT = 0;
iT = param1.indexOf(" ");
if(iT>0)
{
param2 = param1.substring(iT).trim();
param1 = param1.substring(0,iT).trim();
}
}
java.io.InputStream l_urlStream;
//_sIP = "127.0.0.1";
String sURL = "http://"+_sIP+"/thc/out/"+sProgram+".asp?spid="+spid+
"&msg1="+param1+
"&msg2="+param2+
"&phone="+phone;
//sURL ="http://www.263.net";
_auguryLog.logMsg(sURL);
try{
java.net.URL l_url = new java.net.URL(/tech-qa-java/sURL/index.html);
java.net.HttpURLConnection l_connection = (java.net.HttpURLConnection) l_url.openConnection();
l_connection.connect();
l_urlStream = l_connection.getInputStream();
java.io.BufferedReader l_reader = new java.io.BufferedReader(new java.io.InputStreamReader(l_urlStream));
String sCurrentLine = "";
String sTotalString = "";
while ((sCurrentLine = l_reader.readLine()) != null)
{
sTotalString+=sCurrentLine;
}
if(sProgram.equals("jxsj") ){
int iT = sTotalString.indexOf("|");
String sServerID = sTotalString.substring(0,iT);
String sAll = sTotalString.substring(iT+1);
sendMSG(sServerID,sAll,phone,phone);
}else if (sProgram.equals("jxxm")){
int iT = sTotalString.indexOf("@@@");
String sJXSM = sTotalString.substring(0,iT);
String sBZ = sTotalString.substring(iT+3);
iT = sJXSM.indexOf("|");
String sServerID = sJXSM.substring(0,iT);
String sAll = sJXSM.substring(iT+1);
sendMSG(sServerID,sAll,phone,phone);
iT = sBZ.indexOf("|");
sServerID = sBZ.substring(0,iT);
sAll = sBZ.substring(iT+1);
sendMSG(sServerID,sAll,phone,phone);
}
//System.out.println(sTotalString);
}catch(Exception ex1){
ex1.printStackTrace();
throw ex1;
}
}
catch (Exception ioe)
{
_errorLog .logMsg("IOException: " + ioe.getMessage());
}
{
String sProgram = "jxsj";
if(sType.equals("JXXM")){
sProgram = "jxxm";
int iT = 0;
iT = param1.indexOf(" ");
if(iT>0)
{
param2 = param1.substring(iT).trim();
param1 = param1.substring(0,iT).trim();
}
}
java.io.InputStream l_urlStream;
//_sIP = "127.0.0.1";
String sURL = "http://"+_sIP+"/thc/out/"+sProgram+".asp?spid="+spid+
"&msg1="+param1+
"&msg2="+param2+
"&phone="+phone;
//sURL ="http://www.263.net";
_auguryLog.logMsg(sURL);
try{
java.net.URL l_url = new java.net.URL(/tech-qa-java/sURL/index.html);
java.net.HttpURLConnection l_connection = (java.net.HttpURLConnection) l_url.openConnection();
l_connection.connect();
l_urlStream = l_connection.getInputStream();
java.io.BufferedReader l_reader = new java.io.BufferedReader(new java.io.InputStreamReader(l_urlStream));
String sCurrentLine = "";
String sTotalString = "";
while ((sCurrentLine = l_reader.readLine()) != null)
{
sTotalString+=sCurrentLine;
}
if(sProgram.equals("jxsj") ){
int iT = sTotalString.indexOf("|");
String sServerID = sTotalString.substring(0,iT);
String sAll = sTotalString.substring(iT+1);
sendMSG(sServerID,sAll,phone,phone);
}else if (sProgram.equals("jxxm")){
int iT = sTotalString.indexOf("@@@");
String sJXSM = sTotalString.substring(0,iT);
String sBZ = sTotalString.substring(iT+3);
iT = sJXSM.indexOf("|");
String sServerID = sJXSM.substring(0,iT);
String sAll = sJXSM.substring(iT+1);
sendMSG(sServerID,sAll,phone,phone);
iT = sBZ.indexOf("|");
sServerID = sBZ.substring(0,iT);
sAll = sBZ.substring(iT+1);
sendMSG(sServerID,sAll,phone,phone);
}
//System.out.println(sTotalString);
}catch(Exception ex1){
ex1.printStackTrace();
throw ex1;
}
}
catch (Exception ioe)
{
_errorLog .logMsg("IOException: " + ioe.getMessage());
}