Java Code Examples for org.jsoup.Connection#method()

The following examples show how to use org.jsoup.Connection#method() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: JsDroidCmd   File: HttpUtil.java    License: Mozilla Public License 2.0 6 votes vote down vote up
public static String post(String url, Map<String, String> headers,
		Map<String, String> params) {
	try {
		Connection connect = Jsoup.connect(url);
		connect.ignoreContentType(true);
		connect.ignoreHttpErrors(true);
		if (params != null) {
			connect.data(params);
		}
		if (headers != null) {
			connect.headers(headers);
		}
		connect.method(Method.POST);
		return connect.execute().body();
	} catch (Throwable e) {
	}
	return null;
}
 
Example 2
Source Project: WordPressHelper   File: PostComment.java    License: MIT License 6 votes vote down vote up
@Override
protected Object doInBackground(Object[] params) {
    Connection connection  = Jsoup.connect(URL_WORDPRESS + "/wp-comments-post.php");
    connection.method(Connection.Method.POST);
    connection.data("author", name);
    connection.data("email", email);
    connection.data("url", url);
    connection.data("comment", comment);
    connection.data("comment_post_ID", id);
    connection.data("comment_parent", commentParent);
    try {
        response = connection.execute().statusCode();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 3
public static String loadPageSource(PageRequest pageRequest) {
    if (!UrlUtil.isUrl(pageRequest.getUrl())) {
        return null;
    }
    try {
        // 请求设置
        Connection conn = Jsoup.connect(pageRequest.getUrl());
        if (pageRequest.getParamMap() != null && !pageRequest.getParamMap().isEmpty()) {
            conn.data(pageRequest.getParamMap());
        }
        if (pageRequest.getCookieMap() != null && !pageRequest.getCookieMap().isEmpty()) {
            conn.cookies(pageRequest.getCookieMap());
        }
        if (pageRequest.getHeaderMap()!=null && !pageRequest.getHeaderMap().isEmpty()) {
            conn.headers(pageRequest.getHeaderMap());
        }
        if (pageRequest.getUserAgent()!=null) {
            conn.userAgent(pageRequest.getUserAgent());
        }
        if (pageRequest.getReferrer() != null) {
            conn.referrer(pageRequest.getReferrer());
        }
        conn.timeout(pageRequest.getTimeoutMillis());
        conn.validateTLSCertificates(pageRequest.isValidateTLSCertificates());
        conn.maxBodySize(0);    // 取消默认1M限制

        // 代理
        if (pageRequest.getProxy() != null) {
            conn.proxy(pageRequest.getProxy());
        }

        conn.ignoreContentType(true);
        conn.method(pageRequest.isIfPost()?Connection.Method.POST:Connection.Method.GET);

        // 发出请求
        Connection.Response resp = conn.execute();
        String pageSource = resp.body();
        return pageSource;
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
        return null;
    }
}
 
Example 4
@Test public void method() {
    Connection con = HttpConnection.connect("http://example.com/");
    assertEquals(Connection.Method.GET, con.request().method());
    con.method(Connection.Method.POST);
    assertEquals(Connection.Method.POST, con.request().method());
}
 
Example 5
@Test public void method() {
    Connection con = HttpConnection.connect("http://example.com/");
    assertEquals(Connection.Method.GET, con.request().method());
    con.method(Connection.Method.POST);
    assertEquals(Connection.Method.POST, con.request().method());
}
 
Example 6
@Test public void method() {
    Connection con = HttpConnection.connect("http://example.com/");
    assertEquals(Connection.Method.GET, con.request().method());
    con.method(Connection.Method.POST);
    assertEquals(Connection.Method.POST, con.request().method());
}
 
Example 7
Source Project: jsoup-learning   File: HttpConnectionTest.java    License: MIT License 4 votes vote down vote up
@Test public void method() {
    Connection con = HttpConnection.connect("http://example.com/");
    assertEquals(Connection.Method.GET, con.request().method());
    con.method(Connection.Method.POST);
    assertEquals(Connection.Method.POST, con.request().method());
}