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


Java Connection.cookie方法代碼示例

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


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

示例1: getSchoolNotice

import org.jsoup.Connection; //導入方法依賴的package包/類
/**
 * 獲取學校通知接口
 *
 * @param cookiesMap
 * @param index
 * @return
 */
public static Response getSchoolNotice(Map<String, String> cookiesMap, int index) {

    try {
        Connection con = Jsoup.connect(Constant.SchoolNotice.URL);
        con.ignoreContentType(true);
        Iterator<Map.Entry<String, String>> it = cookiesMap.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, String> en = it.next();
            con = con.cookie(en.getKey(), en.getValue());
        }

        return con.method(Connection.Method.POST)
                .data(Constant.SchoolNotice.PARAM_PAGE_SIZE, "10")
                .data(Constant.SchoolNotice.PARAM_PAGE_INDEX, String.valueOf(index))
                .data(Constant.SchoolNotice.PARAM_A_TITLE, "")
                .data(Constant.SchoolNotice.PARAM_ORDER_BY_TYPE, "asc")
                .timeout(10000)
                .execute();

    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:382701145,項目名稱:EducationalAdministrationSystem,代碼行數:32,代碼來源:HttpUtils.java

示例2: getCourseId

import org.jsoup.Connection; //導入方法依賴的package包/類
/**
 * 獲取課程id
 *
 * @param cookiesMap
 * @return
 */
public static Response getCourseId(Map<String, String> cookiesMap) {

    try {
        Connection con = Jsoup.connect(Constant.CoursePraise.COURSE_URL);
        con.ignoreContentType(true);
        Iterator<Map.Entry<String, String>> it = cookiesMap.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, String> en = it.next();
            con = con.cookie(en.getKey(), en.getValue());
        }

        return con.method(Connection.Method.GET)
                .data(Constant.CoursePraise.COURSE_URL_OTHER_PARAM, "zTreeAsyncTest")
                .data(Constant.CoursePraise.COURSE_URL_, "1507812989512")
                .timeout(10000)
                .execute();

    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:382701145,項目名稱:EducationalAdministrationSystem,代碼行數:29,代碼來源:HttpUtils.java

示例3: getCourseInfo

import org.jsoup.Connection; //導入方法依賴的package包/類
public static Response getCourseInfo(Map<String, String> cookiesMap, String id, String name) {

        try {
            Connection con = Jsoup.connect(Constant.CoursePraise.COURSE_URL);
            con.ignoreContentType(true);
            Iterator<Map.Entry<String, String>> it = cookiesMap.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, String> en = it.next();
                con = con.cookie(en.getKey(), en.getValue());
            }

            return con.method(Connection.Method.GET)
                    .data("id", id)
                    .data("name", name)
                    .data("pId", "")
                    .data("level", "0")
                    .data(Constant.CoursePraise.COURSE_URL_OTHER_PARAM, "zTreeAsyncTest")
                    .data(Constant.CoursePraise.COURSE_URL_, "1507812989512")
                    .timeout(10000)
                    .execute();

        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
 
開發者ID:382701145,項目名稱:EducationalAdministrationSystem,代碼行數:27,代碼來源:HttpUtils.java

示例4: doInBackground

import org.jsoup.Connection; //導入方法依賴的package包/類
@Override
protected List<Winner> doInBackground(Void... params) {
    Log.d(TAG, "Fetching giveaways for page " + page);

    try {
        // Fetch the Giveaway page

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

        if (SteamGiftsUserData.getCurrent(fragment.getContext()).isLoggedIn())
            jsoup.cookie("PHPSESSID", SteamGiftsUserData.getCurrent(fragment.getContext()).getSessionId());
        Document document = jsoup.get();

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

        return loadAll(document);
    } catch (IOException e) {
        Log.e(TAG, "Error fetching URL", e);
        return null;
    }
}
 
開發者ID:SteamGifts,項目名稱:SteamGifts,代碼行數:25,代碼來源:LoadGiveawayWinnersTask.java

示例5: get

import org.jsoup.Connection; //導入方法依賴的package包/類
/**
 * Gets the HTML source of a web page.
 * 
 * @param url The URL to scrape.
 * @return A JSoup Document representing the page scraped.
 */
public static Document get(String url) {
	try {
		// before downloading the page, wait for the min delay to pass
		if (timer == null) {
			updateMinDelay();
		} else {
			synchronized (timer) {
				timer.wait();
			}
		}
		
		Connection conn = Jsoup.connect(url);
		
		if (Settings.USE_AUTH && Settings.AUTH_COOKIE != null) {
			// to log in, we need two cookies from the user, called "a" and "b" by FA.
			
			//find cookie A
			Matcher m = Pattern.compile("a=([a-fA-F0-9\\-]+)").matcher(Settings.AUTH_COOKIE);
			if (m.find()) {
				String a = m.group(1);
				conn = conn.cookie("a", a);
			}
			
			//find cookie B
			m = Pattern.compile("b=([a-fA-F0-9\\-]+)").matcher(Settings.AUTH_COOKIE);
			if (m.find()) {
				String b = m.group(1);
				conn = conn.cookie("b", b);
			}
		}
		return conn.get();
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	}
}
 
開發者ID:ThatGreyDragon,項目名稱:who2comm,代碼行數:43,代碼來源:ConnectionManager.java

示例6: getConnection

import org.jsoup.Connection; //導入方法依賴的package包/類
/**
   * Get an object connection with referer and cookie setted
   * @param url url to get
   * @param cookies cookies for the new connection
* @param referer
* @return a connection
*/
  public static Connection getConnection(String url, Map<String, String> cookies, String referer) {
      Connection result = null;
      result = Jsoup.connect(url).method(Method.GET).header("Host", CommonConst.HOST_KRALAND);
      if (referer != null) {
          result.referrer(referer);
      }
      if (cookies != null) {
          for (Map.Entry<String, String> entry : cookies.entrySet()) {
              result.cookie(entry.getKey(), entry.getValue());
          }
      }
      return result;
  }
 
開發者ID:KralandCE,項目名稱:krapi-core,代碼行數:21,代碼來源:Util.java

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

示例8: doInBackground

import org.jsoup.Connection; //導入方法依賴的package包/類
@Override
protected List<Giveaway> doInBackground(Void... params) {
    Log.d(TAG, "Fetching giveaways for user " + path + " on page " + page);

    try {
        // Fetch the Giveaway page
        Connection connection = Jsoup.connect("https://www.steamgifts.com/user/" + path + "/search")
                .userAgent(Constants.JSOUP_USER_AGENT)
                .timeout(Constants.JSOUP_TIMEOUT);
        connection.data("page", Integer.toString(page));
        if (SteamGiftsUserData.getCurrent(fragment.getContext()).isLoggedIn()) {
            connection.cookie("PHPSESSID", SteamGiftsUserData.getCurrent(fragment.getContext()).getSessionId());
            connection.followRedirects(false);
        }

        Connection.Response response = connection.execute();
        Document document = response.parse();

        if (response.statusCode() == 200) {

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

            if (!user.isLoaded())
                foundXsrfToken = Utils.loadUserProfile(user, document);

            // Parse all rows of giveaways
            return Utils.loadGiveawaysFromList(document);
        } else {
            Log.w(TAG, "Got status code " + response.statusCode());
            return null;
        }
    } catch (Exception e) {
        Log.e(TAG, "Error fetching URL", e);
        return null;
    }
}
 
開發者ID:SteamGifts,項目名稱:SteamGifts,代碼行數:37,代碼來源:LoadUserDetailsTask.java

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

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

示例11: connect

import org.jsoup.Connection; //導入方法依賴的package包/類
private Connection.Response connect() throws IOException {
    String url = "https://www.steamgifts.com/discussion/" + discussionId + "/search?page=" + page;
    Log.v(TAG, "Fetching discussion details for " + url);
    Connection connection = Jsoup.connect(url)
            .userAgent(Constants.JSOUP_USER_AGENT)
            .timeout(Constants.JSOUP_TIMEOUT)
            .followRedirects(true);

    if (SteamGiftsUserData.getCurrent(fragment.getContext()).isLoggedIn())
        connection.cookie("PHPSESSID", SteamGiftsUserData.getCurrent(fragment.getContext()).getSessionId());

    return connection.execute();
}
 
開發者ID:SteamGifts,項目名稱:SteamGifts,代碼行數:14,代碼來源:LoadDiscussionDetailsTask.java

示例12: cookie

import org.jsoup.Connection; //導入方法依賴的package包/類
@Test public void cookie() {
    Connection con = HttpConnection.connect("http://example.com/");
    con.cookie("Name", "Val");
    assertEquals("Val", con.request().cookie("Name"));
}
 
開發者ID:cpusoft,項目名稱:common,代碼行數:6,代碼來源:HttpConnectionTest.java

示例13: doInBackground

import org.jsoup.Connection; //導入方法依賴的package包/類
@Override
protected List<Giveaway> doInBackground(Void... params) {
    Log.d(TAG, "Fetching giveaways for page " + page);

    try {
        // Fetch the Giveaway page

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

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

        FilterData filterData = FilterData.getCurrent(fragment.getContext());
        if (!filterData.isEntriesPerCopy()) {
            addFilterParameter(jsoup, "entry_max", filterData.getMaxEntries());
            addFilterParameter(jsoup, "entry_min", filterData.getMinEntries());
        }
        if (!filterData.isRestrictLevelOnlyOnPublicGiveaways()) {
            addFilterParameter(jsoup, "level_min", filterData.getMinLevel());
            addFilterParameter(jsoup, "level_max", filterData.getMaxLevel());
        }
        addFilterParameter(jsoup, "region_restricted", filterData.isRegionRestrictedOnly());
        addFilterParameter(jsoup, "copy_min", filterData.getMinCopies());
        addFilterParameter(jsoup, "copy_max", filterData.getMaxCopies());
        addFilterParameter(jsoup, "point_min", filterData.getMinPoints());
        addFilterParameter(jsoup, "point_max", filterData.getMaxPoints());

        if (type != GiveawayListFragment.Type.ALL)
            jsoup.data("type", type.name().toLowerCase(Locale.ENGLISH));

        if (SteamGiftsUserData.getCurrent(fragment.getContext()).isLoggedIn())
            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.
        if (!showPinnedGiveaways)
            document.select(".pinned-giveaways__outer-wrap").html("");

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

示例14: doInBackground

import org.jsoup.Connection; //導入方法依賴的package包/類
@Override
protected List<Discussion> doInBackground(Void... params) {
    try {
        // Fetch the Giveaway page
        String segment = "";
        if (type != DiscussionListFragment.Type.ALL)
            segment = type.name().replace("_", "-").toLowerCase(Locale.ENGLISH) + "/";
        String url = "https://www.steamgifts.com/discussions/" + segment + "search";

        Log.d(TAG, "Fetching discussions for page " + page + " and URL " + url);

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

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

        // We do not want to follow redirects here, because SteamGifts redirects to the main (giveaways) page if we're not logged in.
        // For all other pages however, if we're not logged in, we're redirected once as well?
        if (type == DiscussionListFragment.Type.CREATED)
            jsoup.followRedirects(false);

        if (SteamGiftsUserData.getCurrent(fragment.getContext()).isLoggedIn())
            jsoup.cookie("PHPSESSID", SteamGiftsUserData.getCurrent(fragment.getContext()).getSessionId());
        Document document = jsoup.get();

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

        // Parse all rows of discussions
        Elements discussions = document.select(".table__row-inner-wrap");
        Log.d(TAG, "Found inner " + discussions.size() + " elements");

        List<Discussion> discussionList = new ArrayList<>();
        for (Element element : discussions) {
            Element link = element.select("h3 a").first();

            // Basic information
            Uri uri = Uri.parse(link.attr("href"));
            String discussionId = uri.getPathSegments().get(1);
            String discussionName = uri.getPathSegments().get(2);

            Discussion discussion = new Discussion(discussionId);
            discussion.setTitle(link.text());
            discussion.setName(discussionName);

            Element p = element.select(".table__column--width-fill p").first();
            discussion.setCreatedTime(Integer.valueOf(p.select("span").first().attr("data-timestamp")));
            discussion.setCreator(p.select("a").last().text());

            // The creator's avatar
            Element avatarNode = element.select(".table_image_avatar").first();
            if (avatarNode != null)
                discussion.setCreatorAvatar(Utils.extractAvatar(avatarNode.attr("style")));

            discussion.setLocked(element.hasClass("is-faded"));
            discussion.setPoll(!element.select("h3 i.fa-align-left").isEmpty());
            discussionList.add(discussion);
        }
        return discussionList;
    } catch (Exception e) {
        Log.e(TAG, "Error fetching URL", e);
        return null;
    }
}
 
開發者ID:SteamGifts,項目名稱:SteamGifts,代碼行數:67,代碼來源:LoadDiscussionListTask.java

示例15: doInBackground

import org.jsoup.Connection; //導入方法依賴的package包/類
@Override
protected List<GiveawayGroup> doInBackground(Void... params) {
    Log.d(TAG, "Fetching giveaways for page " + page);

    try {
        // Fetch the Giveaway page

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

        if (SteamGiftsUserData.getCurrent(fragment.getContext()).isLoggedIn())
            jsoup.cookie("PHPSESSID", SteamGiftsUserData.getCurrent(fragment.getContext()).getSessionId());
        Document document = jsoup.get();

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

        // Parse all rows of groups
        Elements groups = document.select(".table__row-inner-wrap");
        Log.d(TAG, "Found inner " + groups.size() + " elements");

        List<GiveawayGroup> groupList = new ArrayList<>();
        for (Element element : groups) {
            Element link = element.select(".table__column__heading").first();

            // Basic information
            String title = link.text();
            String id = link.attr("href").substring(7, 12);

            String avatar = null;
            Element avatarNode = element.select(".global__image-inner-wrap").first();
            if (avatarNode != null)
                avatar = Utils.extractAvatar(avatarNode.attr("style"));

            GiveawayGroup group = new GiveawayGroup(id, title, avatar);
            groupList.add(group);
        }

        return groupList;
    } catch (IOException e) {
        Log.e(TAG, "Error fetching URL", e);
        return null;
    }
}
 
開發者ID:SteamGifts,項目名稱:SteamGifts,代碼行數:46,代碼來源:LoadGiveawayGroupsTask.java


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