Jsoup发送http请求,get和post两种方式,分别带参数和不带参数
发布网友
发布时间:2023-02-01 06:27
我来回答
共1个回答
热心网友
时间:2024-11-23 15:55
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.10.3</version>
</dependency>
public void JsoupGet() throws Exception{
Connection connect = Jsoup.connect("http://www.itcast.cn?username=zhangsan&password=lisi");
// 带参数开始
connect.data("username","zhangsan");
connect.data("password","lisi");
// 带参数结束
Document document = connect.get();
System.out.println(document.toString());
}
public void JsoupPost() throwsException{
Connection connect = Jsoup.connect("http://www.itcast.cn?username=zhangsan&password=lisi");
// 带参数开始
connect.data("username","zhangsan");
connect.data("password","lisi");
// 带参数结束
Document document = connect.post();
System.out.println(document.toString());
}