本文整理汇总了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();
}
示例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"));
}
示例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;
}
}
示例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();
}
示例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;
}
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
}