当前位置: 首页>>代码示例>>Java>>正文


Java Connection.requestBody方法代码示例

本文整理汇总了Java中org.jsoup.Connection.requestBody方法的典型用法代码示例。如果您正苦于以下问题:Java Connection.requestBody方法的具体用法?Java Connection.requestBody怎么用?Java Connection.requestBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jsoup.Connection的用法示例。


在下文中一共展示了Connection.requestBody方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;

}
 
开发者ID:cpusoft,项目名称:common,代码行数:48,代码来源:HttpServiceImpl.java

示例2: fetch

import org.jsoup.Connection; //导入方法依赖的package包/类
public Connection.Response fetch(Parameters params) throws IOException {

        setProperty("sun.net.http.allowRestrictedHeaders", "true");
        setProperty("javax.net.ssl.trustStore", "/etc/ssl/certs/java/cacerts");

        int retryCount = 0;

        while(true) {
            try {
                final Connection connection = Jsoup
                        .connect(params.getUrlToFetch())
                        .method(params.getMethod())

                        .validateTLSCertificates(false)
                        .ignoreHttpErrors(true)
                        .followRedirects(params.isFollowRedirects())
                        .ignoreContentType(GLOBAL_CONFIG.isIgnoringContentType())

                        .userAgent(params.getUserAgent())
                        .referrer(params.getReferrer())

                        .proxy(createProxy(params.getProxy()))
                        .maxBodySize(0)
                        .timeout(params.getTimeout());

                if (!params.getCookie().isEmpty()) {
                    connection.cookies(params.getCookie());
                }

                if (!params.getHeaders().isEmpty()) {
                    connection.headers(params.getCookie());
                }

                if (!params.getRequestBody().isEmpty()) {
                    connection.requestBody(params.getRequestBody());
                }

                System.out.println("\uD83D\uDD3D " + ansi().fg(CYAN).bold().a("fetched page : ").reset() + params.getUrlToFetch());

                return connection.execute();

            } catch(SocketTimeoutException ste) {
                if(retryCount > params.getRetriesOnTimeout()) {
                    throw ste;
                }
                System.out.println("\uD83D\uDD50 " + ansi().fg(YELLOW).bold().a("fetch timeout: ").reset() + "SocketRead time out after " + retryCount++ + ". try");
            }
        }
    }
 
开发者ID:christian-draeger,项目名称:page-content-tester,代码行数:50,代码来源:Fetcher.java

示例3: requestBody

import org.jsoup.Connection; //导入方法依赖的package包/类
@Test public void requestBody() {
    Connection con = HttpConnection.connect("http://example.com/");
    con.requestBody("foo");
    assertEquals("foo", con.request().requestBody());
}
 
开发者ID:cpusoft,项目名称:common,代码行数:6,代码来源:HttpConnectionTest.java

示例4: 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;
    }
}
 
开发者ID:cpusoft,项目名称:common,代码行数:59,代码来源:JsoupServiceImpl.java


注:本文中的org.jsoup.Connection.requestBody方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。