外卖项目–Springboot回顾Day4
httpclient使用示例
HttpClient是Apache的一个子项目,是高效的、功能丰富的支持HTTP协议的客户端编程工具包。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| @SpringBootTest(classes = SkyApplication.class) public class HttpClientTest {
@Test public void testGET() throws Exception{
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet("http://localhost:8080/user/shop/status");
CloseableHttpResponse response = httpClient.execute(httpGet);
int statusCode = response.getStatusLine().getStatusCode(); System.out.println("服务端返回的状态码为:" + statusCode);
HttpEntity entity = response.getEntity(); String body = EntityUtils.toString(entity); System.out.println("服务端返回的数据为:" + body);
response.close(); httpClient.close(); }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
@Test public void testPOST() throws Exception{ CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("http://localhost:8080/admin/employee/login");
JSONObject jsonObject = new JSONObject(); jsonObject.put("username","admin"); jsonObject.put("password","123456");
StringEntity entity = new StringEntity(jsonObject.toString()); entity.setContentEncoding("utf-8"); entity.setContentType("application/json"); httpPost.setEntity(entity);
CloseableHttpResponse response = httpClient.execute(httpPost);
int statusCode = response.getStatusLine().getStatusCode(); System.out.println("响应码为:" + statusCode);
HttpEntity entity1 = response.getEntity(); String body = EntityUtils.toString(entity1); System.out.println("响应数据为:" + body);
response.close(); httpClient.close(); }
|
微信小程序
小程序包含一个描述整体程序的app和多个描述各自页面的page。
主体部分由三个部分三个文件组成,必须放在项目的根目录
文件 |
必须 |
作用 |
app.js |
是 |
小程序逻辑 |
app.json |
是 |
小程序公共配置 |
app.wxss |
否 |
小程序公共样式表 |
一个小程序页面由四个文件组成
文件 |
必须 |
作用 |
js |
是 |
页面逻辑 |
wxml |
是 |
页面结构 |
json |
否 |
页面配置 |
wxss |
否 |
页面样式表 |
小程序登录流程