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


Java Connection类代码示例

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


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

示例1: saveToFile

import org.jsoup.Connection; //导入依赖的package包/类
public static File saveToFile(String address, String localFileName) throws IOException {
    File       file       = new File(localFileName);
    Connection connection = Jsoup.connect(address).ignoreContentType(true).ignoreHttpErrors(true);
    connection.userAgent("Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36");
    connection.timeout(10000);
    Connection.Response resultImageResponse = connection.execute();
    FileOutputStream    out                 = (new FileOutputStream(file));
    out.write(resultImageResponse.bodyAsBytes());           // resultImageResponse.body() is where the image's contents are.
    out.close();
    return file;
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:12,代码来源:HttpUtils.java

示例2: getWebtoon

import org.jsoup.Connection; //导入依赖的package包/类
/**
 * 웹툰조회
 */
public void getWebtoon(String code) {

	if (!"".equals(code)) {
		CommonService cs = new CommonService();

		Connection conn = cs.getConnection(code);
		conn.timeout(5000);

		Document doc = null;
		
		codeInputField.setText(code);
		wDesc.setWrapText(true);

		try {

			doc = conn.get();

			String title = doc.select("title").text().split("::")[0];
			setTitle(title);

			String author = doc.select("div.detail h2 > span").text();
			wTitle.setText(title + "(" + author + ")");

			String desc = doc.select("div.detail p").text();
			wDesc.setText(desc);

			String img = doc.select("div.thumb > a img").attr("src");
			thumbnail.setImage(new Image(img, true));

		} catch (Exception e) {
			e.printStackTrace();
		}
	} else {
		Platform.runLater(new Runnable() {
			@Override
			public void run() {
				AlertSupport alert = new AlertSupport("웹툰코드를 입력하세요.");
				alert.alertInfoMsg(stage);
			}
		});
	}
}
 
开发者ID:kimyearho,项目名称:WebtoonDownloadManager,代码行数:46,代码来源:ManualController.java

示例3: getUserInfo

import org.jsoup.Connection; //导入依赖的package包/类
private UserInfo getUserInfo() {

        UserInfo userInfo = new UserInfo();

        try {
            Connection.Response customerInfo = Jsoup.connect(VOICEMAIL_SERVICE_URI).cookies(loadCookies()).execute();

            Document doc = customerInfo.parse();

            Elements pseudo = doc.select("input[name=pseudo]");
            Elements phoneNumber = doc.select("input[name=voip_num]");
            Elements login = doc.select("input[name=login]");
            Elements email = doc.select("input[name=email]");
            Elements uid = doc.select("input[name=uid]");

            userInfo.setPseudo((pseudo.size() > 0) ? pseudo.get(0).attr("value") : "");
            userInfo.setPhoneNumber((phoneNumber.size() > 0) ? phoneNumber.get(0).attr("value") : "");
            userInfo.setLogin((login.size() > 0) ? login.get(0).attr("value") : "");
            userInfo.setEmail((email.size() > 0) ? email.get(0).attr("value") : "");
            userInfo.setUid((uid.size() > 0) ? uid.get(0).attr("value") : "");

        } catch (IOException e) {
            e.printStackTrace();
        }
        return userInfo;
    }
 
开发者ID:bertrandmartel,项目名称:bboxapi-voicemail,代码行数:27,代码来源:VoiceMailApi.java

示例4: rip

import org.jsoup.Connection; //导入依赖的package包/类
@Override
public void rip() throws IOException {
    String gid = getGID(this.url);
    String theurl = "http://newsfilter.org/gallery/" + gid;
    logger.info("Loading " + theurl);

    Connection.Response resp = Jsoup.connect(theurl)
        .timeout(5000)
        .referrer("")
        .userAgent(USER_AGENT)
        .method(Connection.Method.GET)
        .execute();
    Document doc = resp.parse();

    Elements thumbnails = doc.select("#galleryImages .inner-block img");
    for (Element thumb : thumbnails) {
        String thumbUrl = thumb.attr("src");
        String picUrl = thumbUrl.replace("thumbs/", "");
        addURLToDownload(new URL(picUrl));
    }

    waitForThreads();
}
 
开发者ID:RipMeApp,项目名称:ripme,代码行数:24,代码来源:NewsfilterRipper.java

示例5: login

import org.jsoup.Connection; //导入依赖的package包/类
private synchronized boolean login() throws IOException {
    log.info("Authenticating to GS admin panel");
    String username = getUsername();
    String password = getPassword();
    rateLimiter.acquire(2);
    Connection.Response loginForm = Jsoup.connect(LOGIN_URL)
        .method(Connection.Method.GET)
        .userAgent(USER_AGENT)
        .execute();
    if (loginForm.statusCode() == 403) {
        log.warn("Disabling panel due to 403");
        enabled = false;
    }
    rateLimiter.acquire(2);
    Document document = Jsoup.connect(LOGIN_URL)
        .userAgent(USER_AGENT)
        .data("logout", "1")
        .data("username", username)
        .data("password", password)
        .data("query_string", "")
        .cookies(loginForm.cookies())
        .post();
    session.clear();
    session.putAll(loginForm.cookies());
    return !isLoginPage(document);
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:27,代码来源:GameAdminService.java

示例6: doInBackground

import org.jsoup.Connection; //导入依赖的package包/类
@Override
@Deprecated
protected List<Elements> doInBackground(String... params) {
    List<Elements> results = new ArrayList<>();
    int idx = 0;
    try {
        Connection.Response response = Jsoup.connect(url())
                .data(data())
                .method(method())
                .cookies(cookies())
                .execute();
        cookies = response.cookies();
        for (String param : params) {
            if (!TextUtils.isEmpty(param)) {
                results.add(response.parse().select(param));
            }
            publishProgress((int) ((double) (++idx / params.length)) * 100);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return results;
}
 
开发者ID:mgilangjanuar,项目名称:GoSCELE,代码行数:24,代码来源:BaseProvider.java

示例7: getWebPreviewFromURL

import org.jsoup.Connection; //导入依赖的package包/类
public static Web getWebPreviewFromURL(String url) throws IllegalArgumentException, IOException {
    Connection.Response response = null;
    Web web = null;

    response = Jsoup.connect(url)
            .userAgent("Mozilla/5.0")
            .ignoreHttpErrors(true)
            .execute();

    if (response.statusCode() != 200) {
        return null;
    }
    web = parseWeb(response);

    return web;
}
 
开发者ID:costular,项目名称:android-url-preview,代码行数:17,代码来源:LinkCrawler.java

示例8: unlockParental

import org.jsoup.Connection; //导入依赖的package包/类
/**
 * Unlock Steam parental controls with a pin
 */
private String unlockParental(String pin) {
    final String url = STEAM_STORE + "parental/ajaxunlock";
    try {
        final Map<String,String> responseCookies = Jsoup.connect(url)
                .referrer(STEAM_STORE)
                .followRedirects(true)
                .ignoreContentType(true)
                .cookies(generateWebCookies())
                .data("pin", pin)
                .method(Connection.Method.POST)
                .execute()
                .cookies();
        return responseCookies.get("steamparental");
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:steevp,项目名称:UpdogFarmer,代码行数:22,代码来源:SteamWebHandler.java

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

示例10: getLoginResponse

import org.jsoup.Connection; //导入依赖的package包/类
/**
 * 登录接口获取响应
 *
 * @param user
 * @return
 */
public static Response getLoginResponse(User user) {

    Map<String, String> map = new HashMap<>();
    map.put(Constant.Login.PARAM_USERNAME, user.getUsername());
    map.put(Constant.Login.PARAM_PASSWORD, user.getPassword());
    try {

        return Jsoup.connect(Constant.Login.LOGIN_URL)
                .data(map)
                .ignoreContentType(true)
                .method(Connection.Method.POST)
                .timeout(10000)
                .execute();

    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:382701145,项目名称:EducationalAdministrationSystem,代码行数:26,代码来源:HttpUtils.java

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

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

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

示例14: onPostExecute

import org.jsoup.Connection; //导入依赖的package包/类
@Override
protected void onPostExecute(Connection.Response response) {
    super.onPostExecute(response);
    if (response != null) {
        String body = response.body();
        if (body != null) {
            // TODO 获取成功,保存到本地
            LogUtils.d(body);
            Type listType = new TypeToken<List<Course.CourseInfo>>() {
            }.getType();
            courseInfoList = gson.fromJson(body, listType);
            // TODO 根据CourseId查询课程信息
            if (!courseInfoList.isEmpty()) {
                for (int i = 0; i < courseInfoList.size(); i++) {
                    new CoursePraiseInfoAsyncTask(context, onLoadCallback).execute(courseInfoList.get(i));
                }
            } else {
                onLoadCallback.onFailed(Constant.Connect.ERROR);
            }
        } else {
            onLoadCallback.onFailed(Constant.Connect.ERROR);
        }
    } else {
        onLoadCallback.onFailed(Constant.Network.Network_ERROR);
    }
}
 
开发者ID:382701145,项目名称:EducationalAdministrationSystem,代码行数:27,代码来源:CoursePraiseModel.java

示例15: GetTotalPages

import org.jsoup.Connection; //导入依赖的package包/类
/**
 * 获取总页数,返回给前台
 * 参数
 *
 * @param cityCode 城市
 * @param minPrice 最低价格
 * @param maxPrice 最高价格
 * @return
 */
@ResponseBody
@RequestMapping(value = "/GetTotalPages", method = RequestMethod.POST)
public int GetTotalPages(String cityCode, int minPrice, int maxPrice, String area, String subway) {
    //构建URL
    String oldUrl = "http://" + cityCode + ".58.com";
    Connection conn = Jsoup.connect(oldUrl);
    int pages = 0;
    try {
        Response response = conn.method(Method.GET).execute();
        newUrl = response.url().toString() + "/pinpaigongyu/pn/";
        String nowUrl = newUrl + "1/?minprice=" + minPrice + "_" + maxPrice + area + subway;
        Document doc = Jsoup.connect(nowUrl).get();
        int listsum = Integer.valueOf(doc.getElementsByClass("listsum").select("em").text());
        pages = listsum % 20 == 0 ? listsum / 20 : listsum / 20 + 1;  //计算页数
    } catch (IOException ex) {

    }
    return pages;
}
 
开发者ID:SkyAndCode,项目名称:HouseSearch,代码行数:29,代码来源:HouseController.java


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