本文整理汇总了Java中org.jsoup.Connection.KeyVal方法的典型用法代码示例。如果您正苦于以下问题:Java Connection.KeyVal方法的具体用法?Java Connection.KeyVal怎么用?Java Connection.KeyVal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jsoup.Connection
的用法示例。
在下文中一共展示了Connection.KeyVal方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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"));
}
示例2: createsFormData
import org.jsoup.Connection; //导入方法依赖的package包/类
@Test public void createsFormData() {
String html = "<form><input name='one' value='two'><select name='three'><option value='not'>" +
"<option value='four' selected><option value='five' selected><textarea name=six>seven</textarea>" +
"<input name='seven' type='radio' value='on' checked><input name='seven' type='radio' value='off'>" +
"<input name='eight' type='checkbox' checked><input name='nine' type='checkbox' value='unset'>" +
"<input name='ten' value='text' disabled>" +
"</form>";
Document doc = Jsoup.parse(html);
FormElement form = (FormElement) doc.select("form").first();
List<Connection.KeyVal> data = form.formData();
assertEquals(6, data.size());
assertEquals("one=two", data.get(0).toString());
assertEquals("three=four", data.get(1).toString());
assertEquals("three=five", data.get(2).toString());
assertEquals("six=seven", data.get(3).toString());
assertEquals("seven=on", data.get(4).toString()); // set
assertEquals("eight=on", data.get(5).toString()); // default
// nine should not appear, not checked checkbox
// ten should not appear, disabled
}
示例3: createsSubmitableConnection
import org.jsoup.Connection; //导入方法依赖的package包/类
@Test public void createsSubmitableConnection() {
String html = "<form action='/search'><input name='q'></form>";
Document doc = Jsoup.parse(html, "http://example.com/");
doc.select("[name=q]").attr("value", "jsoup");
FormElement form = ((FormElement) doc.select("form").first());
Connection con = form.submit();
assertEquals(Connection.Method.GET, con.request().method());
assertEquals("http://example.com/search", con.request().url().toExternalForm());
List<Connection.KeyVal> dataList = (List<Connection.KeyVal>) con.request().data();
assertEquals("q=jsoup", dataList.get(0).toString());
doc.select("form").attr("method", "post");
Connection con2 = form.submit();
assertEquals(Connection.Method.POST, con2.request().method());
}
示例4: adoptedFormsRetainInputs
import org.jsoup.Connection; //导入方法依赖的package包/类
@Test public void adoptedFormsRetainInputs() {
// test for https://github.com/jhy/jsoup/issues/249
String html = "<html>\n" +
"<body> \n" +
" <table>\n" +
" <form action=\"/hello.php\" method=\"post\">\n" +
" <tr><td>User:</td><td> <input type=\"text\" name=\"user\" /></td></tr>\n" +
" <tr><td>Password:</td><td> <input type=\"password\" name=\"pass\" /></td></tr>\n" +
" <tr><td><input type=\"submit\" name=\"login\" value=\"login\" /></td></tr>\n" +
" </form>\n" +
" </table>\n" +
"</body>\n" +
"</html>";
Document doc = Jsoup.parse(html);
FormElement form = (FormElement) doc.select("form").first();
List<Connection.KeyVal> data = form.formData();
assertEquals(3, data.size());
assertEquals("user", data.get(0).key());
assertEquals("pass", data.get(1).key());
assertEquals("login", data.get(2).key());
}
示例5: inputStream
import org.jsoup.Connection; //导入方法依赖的package包/类
@Test public void inputStream() {
Connection.KeyVal kv = HttpConnection.KeyVal.create("file", "thumb.jpg", ParseTest.inputStreamFrom("Check"));
assertEquals("file", kv.key());
assertEquals("thumb.jpg", kv.value());
assertTrue(kv.hasInputStream());
kv = HttpConnection.KeyVal.create("one", "two");
assertEquals("one", kv.key());
assertEquals("two", kv.value());
assertFalse(kv.hasInputStream());
}
示例6: controlsAddedAfterParseAreLinkedWithForms
import org.jsoup.Connection; //导入方法依赖的package包/类
@Test public void controlsAddedAfterParseAreLinkedWithForms() {
Document doc = Jsoup.parse("<body />");
doc.body().html("<form />");
Element formEl = doc.select("form").first();
formEl.append("<input name=foo value=bar>");
assertTrue(formEl instanceof FormElement);
FormElement form = (FormElement) formEl;
assertEquals(1, form.elements().size());
List<Connection.KeyVal> data = form.formData();
assertEquals("foo=bar", data.get(0).toString());
}
示例7: usesOnForCheckboxValueIfNoValueSet
import org.jsoup.Connection; //导入方法依赖的package包/类
@Test public void usesOnForCheckboxValueIfNoValueSet() {
Document doc = Jsoup.parse("<form><input type=checkbox checked name=foo></form>");
FormElement form = (FormElement) doc.select("form").first();
List<Connection.KeyVal> data = form.formData();
assertEquals("on", data.get(0).value());
assertEquals("foo", data.get(0).key());
}
示例8: data
import org.jsoup.Connection; //导入方法依赖的package包/类
@Override
public Connection.Request data(Connection.KeyVal keyval) {
return null;
}