當前位置: 首頁>>代碼示例>>Java>>正文


Java Connection.data方法代碼示例

本文整理匯總了Java中org.jsoup.Connection.data方法的典型用法代碼示例。如果您正苦於以下問題:Java Connection.data方法的具體用法?Java Connection.data怎麽用?Java Connection.data使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jsoup.Connection的用法示例。


在下文中一共展示了Connection.data方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: postPageByUrl

import org.jsoup.Connection; //導入方法依賴的package包/類
public Document postPageByUrl(String url, String[][] params) throws IOException {
    Connection connection = Jsoup.connect(url);

    for (String[] data : params) {
        connection.data(data[0], data[1]);
    }

    Connection.Response response = connection.cookies(getCookies())
            .followRedirects(true)
            .method(Connection.Method.POST)
            .execute();

    this.cookies.addItems(response.cookies());

    return response.parse();
}
 
開發者ID:wulkanowy,項目名稱:wulkanowy,代碼行數:17,代碼來源:Api.java

示例2: postHtmlFile

import org.jsoup.Connection; //導入方法依賴的package包/類
/**
 * Test fetching a form, and submitting it with a file attached.
 */
@Test
public void postHtmlFile() throws IOException {
    Document index = Jsoup.connect("http://direct.infohound.net/tidy/").get();
    FormElement form = index.select("[name=tidy]").forms().get(0);
    Connection post = form.submit();

    File uploadFile = ParseTest.getFile("/htmltests/google-ipod.html");
    FileInputStream stream = new FileInputStream(uploadFile);
    
    Connection.KeyVal fileData = post.data("_file");
    fileData.value("check.html");
    fileData.inputStream(stream);

    Connection.Response res;
    try {
        res = post.execute();
    } finally {
        stream.close();
    }

    Document out = res.parse();
    assertTrue(out.text().contains("HTML Tidy Complete"));
}
 
開發者ID:cpusoft,項目名稱:common,代碼行數:27,代碼來源:UrlConnectTest.java

示例3: 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

示例4: postJspToHtml

import org.jsoup.Connection; //導入方法依賴的package包/類
public void postJspToHtml(String postUrl, String filePath,String fileName) throws Exception{
	HttpServletRequest request=Struts2Utils.getRequest();
	//${pageContext.request.scheme}://${pageContext.request.serverName }:${pageContext.request.serverPort} pageContext.request.contextPath
	String reqTarget = request.getScheme()+"://"+request.getServerName()+(request.getServerPort()==80?"":":"+request.getServerPort())+request.getContextPath();
	reqTarget =reqTarget+"/toHtml";
	//?url="+postUrl+"&filePath="+filePath+"&fileName="+fileName;
	Map<String, String> map=new HashMap<String, String>();
	map.put("url", postUrl);
	map.put("filePath", filePath);
	map.put("fileName", fileName);
	Connection connection = Jsoup.connect(reqTarget);
	connection.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31");
	connection.data(map);
	Document doc=connection.timeout(8000).get();
}
 
開發者ID:wkeyuan,項目名稱:DWSurvey,代碼行數:16,代碼來源:JspToHtml.java

示例5: doInBackground

import org.jsoup.Connection; //導入方法依賴的package包/類
@Override
protected List<IEndlessAdaptable> doInBackground(Void... params) {
    try {
        // Fetch the messages page

        Connection jsoup = Jsoup.connect("https://www.steamgifts.com/messages/search")
                .userAgent(Constants.JSOUP_USER_AGENT)
                .timeout(Constants.JSOUP_TIMEOUT);
        jsoup.data("page", Integer.toString(page));
        jsoup.cookie("PHPSESSID", SteamGiftsUserData.getCurrent(context).getSessionId());

        Document document = jsoup.get();

        SteamGiftsUserData.extract(context, document);

        // Fetch the xsrf token
        Element xsrfToken = document.select("input[name=xsrf_token]").first();
        if (xsrfToken != null)
            foundXsrfToken = xsrfToken.attr("value");

        // Parse all rows of giveaways
        return loadMessages(document);
    } catch (Exception e) {
        Log.e(TAG, "Error fetching URL", e);
        return null;
    }
}
 
開發者ID:SteamGifts,項目名稱:SteamGifts,代碼行數:28,代碼來源:LoadMessagesTask.java

示例6: 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

示例7: findByQuery

import org.jsoup.Connection; //導入方法依賴的package包/類
public List<VizierResult> findByQuery(VizierQuery query) {
    Set<VizierResult> result = new HashSet<>();
    try {
        Connection con = getTemplate()
                .data("-c", query.getQuery());
        if (query.getRadius() != null && query.getRadius().getRadius() != 0) {
            con.data("-c.r", Double.toString(query.getRadius().getRadius()));
            con.data("-c.u", query.getRadius().getUnit().toString());
        }
        result.addAll(parseDoc(con.method(Connection.Method.POST).execute().body()));
        if (result.isEmpty()) {
            con = getTemplate()
                    .data("-c", "")
                    .data("Name", query.getQuery());
            if (query.getRadius() != null && query.getRadius().getRadius() != 0) {
                con.data("-c.r", Double.toString(query.getRadius().getRadius()));
                con.data("-c.u", query.getRadius().getUnit().toString());
            }
            result.addAll(parseDoc(con.method(Connection.Method.POST).execute().body()));
        }
    } catch (IOException e) {
        logger.error(e);
    }
    ArrayList<VizierResult> vizierResults = new ArrayList<>(result);
    vizierResults.sort(Comparator.comparingDouble(VizierResult::getDistance));
    return vizierResults;
}
 
開發者ID:m-krajcovic,項目名稱:photometric-data-retriever,代碼行數:28,代碼來源:VizierResolverTsvImpl.java

示例8: submit

import org.jsoup.Connection; //導入方法依賴的package包/類
private boolean submit() throws IOException {
    Connection connection = Jsoup.connect(SERVER_URL)
            .ignoreContentType(true)
            .timeout(TIME_OUT)
            .data("description", mDescription)
            .data("user_email", mUserEmail)
            .data("user_qq", mUserQQ)
            .data("level", String.valueOf(mLevel))
            .data("app_title", mAppTitle)
            .data("app_package", mAppPackage)
            .data("app_version", mAppVersion)
            .data("device_imei", mDeviceImei)
            .data("device_model", mDeviceModel)
            .data("system_version", mSystemVersion);

    if(!mAppAttachment.equals(""))
    {
        File file = new File(mAppAttachment);
        connection.data("app_attachment", file.getName(), new FileInputStream(file));
    }
    String json = connection.post().text();
    try {
        JSONObject jsonObject = new JSONObject(json);
        return jsonObject.getBoolean("result");
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return false;
}
 
開發者ID:hfutxqd,項目名稱:feedback_android_aar,代碼行數:30,代碼來源:Feedback.java

示例9: createPostStringConnection

import org.jsoup.Connection; //導入方法依賴的package包/類
/**
 * 構建一個請求類型為POST,返回類型為String的抓取連接
 */
public static Connection createPostStringConnection(boolean isUseProxy, String url, String cookie, String UA, String referer, String host,
                                                    String... postData) {
    Connection connection = createStringConnection(isUseProxy, url, cookie, UA, referer, host);
    connection.method(Connection.Method.POST);
    connection.data(postData);
    return connection;
}
 
開發者ID:MartinDai,項目名稱:TBSpider,代碼行數:11,代碼來源:HttpUtils.java

示例10: getListOfSyncProducts

import org.jsoup.Connection; //導入方法依賴的package包/類
@Override
public Response<SyncProduct> getListOfSyncProducts(SyncStatus status, int offset, int limit) {
    Connection connection = LibUtils.createConnection(base64Key, "sync/products", configuration);

    if (status != null) {
        connection.data("status", status.toString());
    }

    if (offset > 0) {
        connection.data("offset", String.valueOf(offset));
    }

    if (limit > 0) {
        if (limit > 100) {
            limit = 100;
        }
        connection.data("limit", String.valueOf(limit));
    }

    try {
        String response = connection.execute().body();
        Type type = new TypeToken<Response<SyncProduct>>() {
        }.getType();
        return LibUtils.gson.fromJson(response, type);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:clayfish,項目名稱:printful4j,代碼行數:30,代碼來源:EComPlatformSyncApiClient.java

示例11: getListOfOrders

import org.jsoup.Connection; //導入方法依賴的package包/類
@Override
public Response<Order> getListOfOrders(OrderStatus status, int offset, int limit) {
    try {
        Connection connection = LibUtils.createConnection(base64Key, "orders", configuration);

        if (status != null) {
            connection.data("status", status.toString());
        }

        if (offset > 0) {
            connection.data("offset", String.valueOf(offset));
        }

        if (limit > 0) {
            if (limit > 100) {
                limit = 100;
            }
            connection.data("limit", String.valueOf(limit));
        }

        return createResponseFromApi(connection.execute().body());
    } catch (IOException e) {
        Log.e(TAG, "Error occurred while getting list of orders.", e);
    }

    return null;
}
 
開發者ID:clayfish,項目名稱:printful4j,代碼行數:28,代碼來源:OrdersApiClient.java

示例12: getListOfFiles

import org.jsoup.Connection; //導入方法依賴的package包/類
@Override
public Response<File> getListOfFiles(FileStatus status, int offset, int limit) {
    try {
        Connection connection = LibUtils.createConnection(base64Key, "files", configuration);

        if (status != null) {
            connection.data("status", status.toString());
        }

        if (offset > 0) {
            connection.data("offset", String.valueOf(offset));
        }

        if (limit > 0) {
            if (limit > 100) {
                limit = 100;
            }
            connection.data("limit", String.valueOf(limit));
        }

        Type type = new TypeToken<Response<File>>() {
        }.getType();
        return LibUtils.gson.fromJson(connection.execute().body(), type);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:clayfish,項目名稱:printful4j,代碼行數:29,代碼來源:FileLibraryApiClient.java

示例13: doInBackground

import org.jsoup.Connection; //導入方法依賴的package包/類
@Override
protected List<BasicUser> doInBackground(Void... params) {
    try {
        // Fetch the Giveaway page
        String url = "https://www.steamgifts.com/account/manage/" + what.name().toLowerCase(Locale.ENGLISH) + "/search";
        Log.d(TAG, "Fetching URL " + url);

        Connection jsoup = Jsoup.connect(url)
                .userAgent(Constants.JSOUP_USER_AGENT)
                .timeout(Constants.JSOUP_TIMEOUT)
                .followRedirects(false);
        jsoup.data("page", Integer.toString(page));

        if (searchQuery != null)
            jsoup.data("q", searchQuery);

        jsoup.cookie("PHPSESSID", SteamGiftsUserData.getCurrent(fragment.getContext()).getSessionId());

        Document document = jsoup.get();

        SteamGiftsUserData.extract(fragment.getContext(), document);

        // Fetch the xsrf token
        Element xsrfToken = document.select("input[name=xsrf_token]").first();
        if (xsrfToken != null)
            foundXsrfToken = xsrfToken.attr("value");

        // Do away with pinned giveaways.
        document.select(".pinned-giveaways__outer-wrap").html("");

        // Parse all rows of giveaways
        return loadAll(document);
    } catch (Exception e) {
        Log.e(TAG, "Error fetching URL", e);
        return null;
    }
}
 
開發者ID:SteamGifts,項目名稱:SteamGifts,代碼行數:38,代碼來源:LoadWhitelistBlacklistTask.java

示例14: 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

示例15: doInBackground

import org.jsoup.Connection; //導入方法依賴的package包/類
@Override
protected List<IEndlessAdaptable> doInBackground(Void... params) {
    try {
        // Fetch the Giveaway page

        Connection jsoup = Jsoup.connect("https://www.steamgifts.com/" + pathSegment + "/search")
                .userAgent(Constants.JSOUP_USER_AGENT)
                .timeout(Constants.JSOUP_TIMEOUT);
        jsoup.data("page", Integer.toString(page));

        if (searchQuery != null)
            jsoup.data("q", searchQuery);

        jsoup.cookie("PHPSESSID", SteamGiftsUserData.getCurrent(context).getSessionId());

        Document document = jsoup.get();

        SteamGiftsUserData.extract(context, document);

        // Fetch the xsrf token
        Element xsrfToken = document.select("input[name=xsrf_token]").first();
        if (xsrfToken != null)
            foundXsrfToken = xsrfToken.attr("value");

        // Do away with pinned giveaways.
        document.select(".pinned-giveaways__outer-wrap").html("");

        // Parse all rows of giveaways
        return loadAll(document);
    } catch (Exception e) {
        Log.e(TAG, "Error fetching URL", e);
        return null;
    }
}
 
開發者ID:SteamGifts,項目名稱:SteamGifts,代碼行數:35,代碼來源:LoadGameListTask.java


注:本文中的org.jsoup.Connection.data方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。