java代理获取页面内容

应用需求:自动归档,将需要归档的文档的页面(是整个html)存为附件,放在归档后的文档中。
    // 连接地址(取得联系L) 
 String surl = "http://oatest.fj.cmcc/names.nsf?login"; 
 URL url = new URL(surl); 
 HttpURLConnection.setFollowRedirects(false);
 HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 
 connection.setDoOutput(true); 
 OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream()); 
               //其中的memberName和password也是阅读html代码得知的,即为表单中对应的参数名称  
 out.write("UserName=zhukongrenyuan&Password=a"); // post的关键所在!  
 out.flush(); 
    out.close(); 
    connection.connect();
 String cookieVal = connection.getHeaderField("Set-Cookie");  
 Session session = getSession();
AgentContext agentContext = session.getAgentContext();

Database db = agentContext.getCurrentDatabase();
URL ibmURL = new URL("http://oatest.fj.cmcc/SGSOA/fwglcx.nsf/0/4825781B006DF1E5482579E6000853E6?opendocument");
HttpURLConnection resumeConnection = (HttpURLConnection) ibmURL.openConnection(); 
if (cookieVal != null) { 
                      //发送cookie信息上去,以表明自己的身份,否则会被认为没有权限  
   resumeConnection.setRequestProperty("Cookie", cookieVal); 


resumeConnection.connect(); 
InputStream urlStream = resumeConnection.getInputStream(); 
BufferedReader bin = new BufferedReader(new InputStreamReader(urlStream)); 

//BufferedReader bin = new BufferedReader ( new InputStreamReader(ibmURL.openStream( ) ));
String line;
StringBuffer sb = new StringBuffer();

while ( (line = bin.readLine( )) != null )
{
sb.append(line);
}
String ibmString = sb.toString();

Document newNotesDoc = db.createDocument();
newNotesDoc.replaceItemValue ("Form", "IBMForm");
newNotesDoc.replaceItemValue ("WebPageUS", ibmString);
newNotesDoc.computeWithForm( true , false);
newNotesDoc.save( true, true );
newNotesDoc.recycle(); 
db.recycle();
} catch(Exception e) {
e.printStackTrace();
}
}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值