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


Java Connection.post方法代码示例

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


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

示例1: loadParse

import org.jsoup.Connection; //导入方法依赖的package包/类
/**
 * 按照规则,加载解析html
 * @param url		:加载URL
 * @param paramMap	:请求参数
 * @param cookieMap	:请求cookie
 * @param ifPost	:是否使用post请求
 * @param tagMap	:解析规则[0-选择器方式、1-id方式、2-class方式、3-tag]
 * @return
 */
public static Elements loadParse(String url, Map<String, String> paramMap, Map<String, String> cookieMap,
        boolean ifPost, Map<Integer, Set<String>> tagMap) {
    if (!isUrl(url)) {
        return null;
    }
    try {
        // 请求设置
        Connection conn = Jsoup.connect(url);
        conn.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36");
        if (paramMap != null && !paramMap.isEmpty()) {
            conn.data(paramMap);
        }
        if (cookieMap != null && !cookieMap.isEmpty()) {
            conn.cookies(cookieMap);
        }
        conn.timeout(5000);

        // 发出请求
        Document html = null;
        if (ifPost) {
            html = conn.post();
        } else {
            html = conn.get();
        }

        // 过滤元素
        Elements resultAll = new Elements();
        if (tagMap != null && !tagMap.isEmpty()) {
            for (Entry<Integer, Set<String>> tag : tagMap.entrySet()) {
                int tagType = tag.getKey();
                Set<String> tagNameList = tag.getValue();
                if (tagNameList != null && tagNameList.size() > 0) {
                    for (String tagName : tagNameList) {
                        if (tagType == 0) {
                            Elements resultSelect = html.select(tagName);	// 选择器方式
                            resultAll.addAll(resultSelect);
                        } else if (tagType == 1) {
                            Element resultId = html.getElementById(tagName);	// 元素ID方式
                            resultAll.add(resultId);
                        } else if (tagType == 2) {
                            Elements resultClass = html.getElementsByClass(tagName);	// ClassName方式
                            resultAll.addAll(resultClass);
                        } else if (tagType == 3) {
                            Elements resultTag = html.getElementsByTag(tagName);	// html标签方式
                            resultAll.addAll(resultTag);
                        }
                    }
                }

            }

        } else {
            resultAll = html.getElementsByTag("body");
        }
        return resultAll;
    } catch (IOException e) {
        logger.error("", e);
    }

    return null;
}
 
开发者ID:xuxueli,项目名称:xxl-incubator,代码行数:71,代码来源:JsoupUtil.java

示例2: load

import org.jsoup.Connection; //导入方法依赖的package包/类
/**
 * 加载页面
 *
 * @param pageLoadInfo
 *
 * @return
 */
public static Document load(PageLoadInfo pageLoadInfo) {
    if (!UrlUtil.isUrl(pageLoadInfo.getUrl())) {
        return null;
    }
    try {
        // 请求设置
        Connection conn = Jsoup.connect(pageLoadInfo.getUrl());
        if (pageLoadInfo.getParamMap() != null && !pageLoadInfo.getParamMap().isEmpty()) {
            conn.data(pageLoadInfo.getParamMap());
        }
        if (pageLoadInfo.getCookieMap() != null && !pageLoadInfo.getCookieMap().isEmpty()) {
            conn.cookies(pageLoadInfo.getCookieMap());
        }
        if (pageLoadInfo.getHeaderMap()!=null && !pageLoadInfo.getHeaderMap().isEmpty()) {
            conn.headers(pageLoadInfo.getHeaderMap());
        }
        if (pageLoadInfo.getUserAgent()!=null) {
            conn.userAgent(pageLoadInfo.getUserAgent());
        }
        if (pageLoadInfo.getReferrer() != null) {
            conn.referrer(pageLoadInfo.getReferrer());
        }
        conn.timeout(pageLoadInfo.getTimeoutMillis());

        // 代理
        if (pageLoadInfo.getProxy() != null) {
            conn.proxy(pageLoadInfo.getProxy());
        }

        // 发出请求
        Document html = null;
        if (pageLoadInfo.getIfPost()) {
            html = conn.post();
        } else {
            html = conn.get();
        }
        return html;
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
        return null;
    }
}
 
开发者ID:xuxueli,项目名称:xxl-crawler,代码行数:50,代码来源:JsoupUtil.java

示例3: readData

import org.jsoup.Connection; //导入方法依赖的package包/类
private void readData(String lct_tstep, String name, String... args) throws IOException, FitsException {
    String searchFormUrl = "https://sdc.cab.inta-csic.es/omc/secure/form_busqueda.jsp?resetForm=true";
    String searchUrl = "https://sdc.cab.inta-csic.es/omc/secure/form_busqueda.jsp";
    Connection.Response form = Jsoup.connect(searchFormUrl).method(Connection.Method.GET).execute();
    Connection post = Jsoup.connect(searchUrl)
            .data("cookieexists", "false")
            .data("submit", "Submit")
            .data("lct_tstep", lct_tstep)
            .data("lct_wcsflag", "Y")
            .data("obj_sstar", "S")
            .data("crv_numpoints", "1")
            .data("obj_prio", "1")
            .data("otuput_format", "html")
            .data("results_per_page", "50")
            .data("page_to_show", "1")
            .cookies(form.cookies());

    if (args.length == 1) { // je to nazov
        post.data("obj_id", args[0]);
    } else if (args.length == 2) { // su to suradnice
        post.data("ra", args[0])
                .data("de", args[1])
                .data("rad", "1");
    } else {
        return;
    }
    Document doc = post.post();
    Element fetchAnchor = doc.getElementsByAttributeValueStarting("href", "fetch_lcurve.jsp?obj_id=").first();
    String href = fetchAnchor.attr("abs:href");
    URL fetchUrl = new URL(href);
    try (InputStream is = PluginUtils.copyUrlOpenStream(fetchUrl, "OMC-" + PluginUtils.getQueryMap(fetchUrl.getQuery()).getOrDefault("obj_id", "-" + System.currentTimeMillis()) + ".fits", 3)) {
        Fits fits = new Fits(is);
        TableHDU table = (TableHDU) fits.getHDU(1);
        float[] mags = (float[]) table.getColumn("MAG_V");
        float[] errs = (float[]) table.getColumn("ERRMAG_V");
        double[] barytimes = (double[]) table.getColumn("BARYTIME");
        double[] telapses = (double[]) table.getColumn("TELAPSE");

        for (int i = 0; i < mags.length; i++) {
            double jd = barytimes[i] + 2451544.5 + telapses[i] / 2 / 86400;
            System.out.println(jd + "," + mags[i] + "," + errs[i] + "," + name);
        }
    }

}
 
开发者ID:m-krajcovic,项目名称:photometric-data-retriever,代码行数:46,代码来源:Main.java

示例4: followsRelativeDotRedirect

import org.jsoup.Connection; //导入方法依赖的package包/类
@Test
public void followsRelativeDotRedirect() throws IOException {
    // redirects to "./ok.html", should resolve to http://direct.infohound.net/tools/ok.html
    Connection con = Jsoup.connect("http://direct.infohound.net/tools/302-rel-dot.pl"); // to ./ok.html
    Document doc = con.post();
    assertTrue(doc.title().contains("OK"));
    assertEquals(doc.location(), "http://direct.infohound.net/tools/ok.html");
}
 
开发者ID:cpusoft,项目名称:common,代码行数:9,代码来源:UrlConnectTest.java

示例5: followsRelativeDotRedirect2

import org.jsoup.Connection; //导入方法依赖的package包/类
@Test
public void followsRelativeDotRedirect2() throws IOException {
    //redirects to "esportspenedes.cat/./ep/index.php", should resolve to "esportspenedes.cat/ep/index.php"
    Connection con = Jsoup.connect("http://esportspenedes.cat")  // note lack of trailing / - server should redir to / first, then to ./ep/...; but doesn't'
            .timeout(10000);
    Document doc = con.post();
    assertEquals(doc.location(), "http://esportspenedes.cat/ep/index.php");
}
 
开发者ID:cpusoft,项目名称:common,代码行数:9,代码来源:UrlConnectTest.java

示例6: createSubscriptionFolder

import org.jsoup.Connection; //导入方法依赖的package包/类
public static void createSubscriptionFolder(Context context, final String foldername) {
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
    final String securityToken = sharedPref.getString("securitytoken", null);
    final String bb_sessionhash = Cookies.getCookie("https://facepunch.com/", "bb_sessionhash");
    final String bb_password = Cookies.getCookie("https://facepunch.com/", "bb_password");
    final String bb_userid = Cookies.getCookie("https://facepunch.com/", "bb_userid");

    Thread t = new Thread(new Runnable() {
        public void run() {
            try {
                Connection doc = Jsoup.connect("https://facepunch.com/subscription.php?do=doeditfolders")
                        .cookie("bb_sessionhash", bb_sessionhash)
                        .cookie("bb_password", bb_password)
                        .cookie("bb_userid", bb_userid)
                        .data("folderid", "0")
                        .data("s", "")
                        .data("securitytoken", securityToken)
                        .data("do", "doeditfolders");

                int Count = 0;

                ArrayList<SubscriptionFolder> currentfolders = getSubscriptionFolders();

                SubscriptionFolder newFolder = new SubscriptionFolder();
                newFolder.setId(currentfolders.size() + 1);
                newFolder.setName(foldername);

                currentfolders.add(newFolder);

                for (SubscriptionFolder folder : currentfolders) {

                    doc.data("folderlist["+Count+"]", folder.getName());
                    Log.d("folder", "folderlist["+Count+"] " + folder.getName());

                    Count++;
                }

                doc.post();

            } catch (IOException e) {
                e.printStackTrace();
            }


        }
    });

    t.start();
}
 
开发者ID:dasmikko,项目名称:facepunchdroid,代码行数:50,代码来源:Subscription.java

示例7: followsRelativeRedirect

import org.jsoup.Connection; //导入方法依赖的package包/类
@Test
public void followsRelativeRedirect() throws IOException {
    Connection con = Jsoup.connect("http://direct.infohound.net/tools/302-rel.pl"); // to /tidy/
    Document doc = con.post();
    assertTrue(doc.title().contains("HTML Tidy Online"));
}
 
开发者ID:cpusoft,项目名称:common,代码行数:7,代码来源:UrlConnectTest.java


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