本文整理匯總了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;
}
}