java源码使用URL来读取网页内容.doc

上传人:自*** 文档编号:126241720 上传时间:2020-03-23 格式:DOC 页数:2 大小:38.45KB
返回 下载 相关 举报
java源码使用URL来读取网页内容.doc_第1页
第1页 / 共2页
java源码使用URL来读取网页内容.doc_第2页
第2页 / 共2页
亲,该文档总共2页,全部预览完了,如果喜欢就下载吧!
资源描述

《java源码使用URL来读取网页内容.doc》由会员分享,可在线阅读,更多相关《java源码使用URL来读取网页内容.doc(2页珍藏版)》请在金锄头文库上搜索。

1、package network;import java.io.BufferedInputStream;import java.io.DataOutputStream;import java.io.InputStream;import java.io.InputStreamReader;import java.io.Reader;import .HttpURLConnection;import .URL;import .URLEncoder;public class GetDataByURL public static String cc(String leibie, String num) S

2、tringBuffer temp = new StringBuffer(); try System.out.println(leibie); System.out.println(num); String url = http:/192.168.7.228:7890/oa/themes/mskin/login/login.jsp; HttpURLConnection uc = (HttpURLConnection)new URL(url). openConnection(); uc.setConnectTimeout(10000); uc.setDoOutput(true); uc.setRe

3、questMethod(GET); uc.setUseCaches(false); DataOutputStream out = new DataOutputStream(uc.getOutputStream(); / 瑕佷紶鐨勫弬鏁?/* String s = URLEncoder.encode(ra, GB2312) + = + URLEncoder.encode(leibie, GB2312); s += & + URLEncoder.encode(keyword, GB2312) + = + URLEncoder.encode(num, GB2312);*/ String s = UR

4、LEncoder.encode(ra, UTF-8) + = + URLEncoder.encode(leibie, UTF-8); s += & + URLEncoder.encode(keyword, UTF-8) + = + URLEncoder.encode(num, UTF-8); / DataOutputStream.writeBytes灏嗗瓧绗覆涓殑16浣嶇殑unicode瀛楃浠?浣嶇殑瀛楃褰紡鍐欓亾娴侀噷闈? out.writeBytes(s); out.flush(); out.close(); InputStream in = new BufferedInputStream(uc.getInputStream(); Reader rd = new InputStreamReader(in, UTF-8); int c = 0; while (c = rd.read() != -1) temp.append(char) c); System.out.println(temp.toString(); in.close(); catch (Exception e) e.printStackTrace(); return temp.toString(); public static void main(String a)GetDataByURL.cc(1,鍚塇);

展开阅读全文
相关资源
相关搜索

当前位置:首页 > IT计算机/网络 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号