本文整理汇总了Java中org.jsoup.Connection.url方法的典型用法代码示例。如果您正苦于以下问题:Java Connection.url方法的具体用法?Java Connection.url怎么用?Java Connection.url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jsoup.Connection
的用法示例。
在下文中一共展示了Connection.url方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connectReuse
import org.jsoup.Connection; //导入方法依赖的package包/类
/**
* @desc 进行实际的链接
* @date 2015年8月17日-下午4:54:23
* @param url
* @param referrer
* @param postDataCharset
* @param isPost
* @param dataMap
* @param proxyIp
* @param proxyPort
* @return Response
*/
@Override
public Connection connectReuse(Connection lastCon,HttpForm httpForm) {
long start = System.currentTimeMillis();
Connection connect = null;
if(lastCon==null){
connect = Jsoup.connect(httpForm.getUrl());
}else{
connect = lastCon.url(httpForm.getUrl());
}
connect = connect
.userAgent(config.getString("common.http.user.agent",DEFAULT_USER_AGENT))
.timeout(config.getInt("common.http.timeout.ms",DEFAULT_TIMEOUT))
.followRedirects(true)
.referrer(httpForm.getReferrer())
.postDataCharset(httpForm.getCharset())
.validateTLSCertificates(false)
.ignoreContentType(true)
.method(httpForm.getMethod());
if(httpForm.getDataMap()!=null && httpForm.getDataMap().size()>0){
connect = connect.data(httpForm.getDataMap());
}
if(StringUtils.isNotBlank(httpForm.getDataString())){
connect = connect.requestBody(httpForm.getDataString());
}
if(StringUtils.isNotBlank(httpForm.getProxyIp()) && httpForm.getProxyPort() > 0) {
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(httpForm.getProxyIp(), httpForm.getProxyPort()));
connect = connect.proxy(proxy);
}
long end = System.currentTimeMillis();
logger.debug("connectReuse():time:"+(end-start)+"ms");
return connect;
}
示例2: connectReuse
import org.jsoup.Connection; //导入方法依赖的package包/类
/**
* @desc 进行实际的链接
* @date 2015年8月17日-下午4:54:23
* @param url
* @param referrer
* @param postDataCharset
* @param isPost
* @param dataMap
* @param proxyIp
* @param proxyPort
* @return Response
*/
@Override
public Connection connectReuse(Connection lastCon,String url,String referrer,String postDataCharset,boolean isPost,Map dataMap,String dataString,
String proxyIp,int proxyPort){
try{
Method method= null;
if(isPost){
method = Method.POST;
}else{
method = Method.GET;
}
Connection connect = null;
if(lastCon==null){
connect = Jsoup.connect(url);
}else{
connect = lastCon.url(url);
}
connect = connect
.userAgent(config.getString("common.http.user.agent",DEFAULT_USER_AGENT))
.timeout(config.getInt("common.http.timeout.ms",DEFAULT_TIMEOUT))
.followRedirects(true)
.referrer(referrer)
.postDataCharset(postDataCharset)
.validateTLSCertificates(false)
.ignoreContentType(true)
.method(method);
if(dataMap!=null && dataMap.size()>0){
connect = connect.data(dataMap);
}
if(StringUtils.isNotBlank(dataString)){
connect = connect.requestBody(dataString);
}
if(StringUtils.isNotBlank(proxyIp) && proxyPort > 0) {
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyIp, proxyPort));
connect = connect.proxy(proxy);
}
return connect;
} catch (Exception e) {
logger.error("connectImpl():exception:url:"+url+" referrer:"+referrer+
" postDataCharset:"+postDataCharset+ " isPost:"+isPost+
" dataMap:"+dataMap+" e:"+e.getMessage(),e);
return null;
}
}