Java实现连续访问网站_java用url类实现的某个网站能不能被访问

package test;

import java.io.IOException;

import java.io.OutputStream;

import java.net.MalformedURLException;

import java.net.URL;

import java.net.URLConnection;

import java.util.HashMap;

import java.util.Iterator;

import java.util.List;

import java.util.Map;

import java.util.Set;

public class URLTest {

/**

* @param args

*/

public static void main(String[] args) {

// TODO 自动生成的方法存根

Map> map = new HashMap();

String surl = "http://www.baidu.com/";

// String surl = "http://www.sina.com.cn/";

// String surl = "https://ebank.xxxxx.com/pweb/test.do?actionType=1"; //不可以

try {

URL url = new URL(surl);

URLConnection urlc = url.openConnection();

map = urlc.getHeaderFields();

Set key = map.keySet();

for(Iterator it = key.iterator();it.hasNext();) {

String s = it.next();

System.out.println(s + " : " +map.get(s));

}

System.out.println("*************************************************");

} catch (MalformedURLException e) {

// TODO 自动生成的 catch 块

e.printStackTrace();

} catch (IOException e) {

// TODO 自动生成的 catch 块

e.printStackTrace();

}

}

}

下面为header结果:

null : [HTTP/1.1 200 OK]

Expires : [Fri, 13 Dec 2013 04:42:19 GMT]

Set-Cookie : [H_PS_PSSID=1430; path=/; domain=.baidu.com, BDSVRTM=0; path=/, BDRCVFR[EaNsStaiD7m]=aeXf-1x8UdYcs; path=/; domain=.baidu.com, BAIDUID=C5E95A03CB761EB5CBB3C0C5ACE499A9:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com]

Connection : [Keep-Alive]

Server : [BWS/1.1]

Cache-Control : [private]

Date : [Fri, 13 Dec 2013 04:42:39 GMT]

BDQID : [0x7467cd8a6929d015]

Vary : [Accept-Encoding]

Transfer-Encoding : [chunked]

P3P : [CP=" OTI DSP COR IVA OUR IND COM ", CP=" OTI DSP COR IVA OUR IND COM "]

BDPAGETYPE : [1]

Content-Type : [text/html]

BDUSERID : [0]

*************************************************

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值