當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。