1.Get方式带参数传递
public class HttpGetParamTest {
public static void main(String[] args) throws URISyntaxException {
//创建httpclient对象
CloseableHttpClient httpClient = HttpClients.createDefault();
//设置请求地址是:https://www.ziroom.com/z/r1/?isOpen=0
//创建URIBuilder
URIBuilder uriBuilder = new URIBuilder("https://www.ziroom.com/z/r1/");
//设置参数
uriBuilder.setParameter("isOpen","0");
//创建httpget对象, 设置url访问地址
HttpGet httpGet = new HttpGet(uriBuilder.build());
System.out.println("发起请求的信息:"+httpGet);
//使用httpclient发起请求
CloseableHttpResponse response = null;
try {
response = httpClient.execute

本文介绍了使用Java进行网络请求时的GET和POST方式参数传递。对于GET方式,通过URIBuilder设置参数并构建HttpGet对象;对于POST方式,利用NameValuePair创建表单数据,通过UrlEncodedFormEntity封装,最后在HttpPost中设置实体。
最低0.47元/天 解锁文章
881

被折叠的 条评论
为什么被折叠?



