博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
httpclient post 发送Json数据
阅读量:7112 次
发布时间:2019-06-28

本文共 1068 字,大约阅读时间需要 3 分钟。

hot3.png

        String url = "http://127.0.0.1:8099/login";	String json = "{\"login_name\": \"18800000000\",\"login_password\": \"123456\"}";	@Test	public void post() throws ClientProtocolException, IOException{		//创建client		CloseableHttpClient httpclient = HttpClients.createDefault();		try {			//创建post请求			HttpPost httppost = new HttpPost(url);			//json			StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);			httppost.setEntity(entity);			System.out.println("executing request " + httppost.getRequestLine());			//执行post请求			CloseableHttpResponse response = httpclient.execute(httppost);			try {				System.out.println("----------------------------------------");				//状态				System.out.println(response.getStatusLine());				//响应实体				HttpEntity resEntity = response.getEntity();				if (resEntity != null) {					System.out.println(EntityUtils.toString(resEntity));				}				//关闭HttpEntity流				EntityUtils.consume(resEntity);			} finally {				response.close();			}		} finally {			httpclient.close();		}	}

转载于:https://my.oschina.net/u/2385255/blog/552275

你可能感兴趣的文章
MyEclipse 2014 加速启动设置
查看>>
UI设计师都关注的字体设计技巧
查看>>
Gdtool为您解答微信公众号手机无法直接下载APK文件是怎么回事
查看>>
apache下mod_jk模块学习随笔
查看>>
Android学习--03-活动
查看>>
VMware-workstation-full-9.0.0-812388附注册机
查看>>
重新安装.net framework 4.5
查看>>
常用开发资源收集
查看>>
年近30,朋友聚会都聊什么?
查看>>
发布jar包至maven本地库及私服
查看>>
Xshell 创建RSA登录Linux 主机
查看>>
非常酷的国外网站导航设计案例欣赏
查看>>
ASP.NET身份验证的探讨
查看>>
Java反射与注解
查看>>
判断一个数是否为回文数,字符串是否为回文字符串
查看>>
Windows Live Writer 2009 客户端离线写51CTO博客
查看>>
date_default_timezone_set的问题
查看>>
不安装oracle客户端,用plsql连接oracle
查看>>
让孩子爱上学习-获取安卓
查看>>
[iOS Animation]CALayer-图层时间 二
查看>>