同时下载多个文件
curl -o save.txt http://localhost:8080/simple-service-webapp/test/hello
-o save2.txt http://localhost:8080/simple-service-webapp/test/hello2
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/doGet")
public Response doGet(@QueryParam("name") String name, @Context HttpHeaders httpHeader, @Context UriInfo uriInfo) {
// 请求头
String contentType = httpHeader.getHeaderString("Content-Type");
String token = httpHeader.getHeaderString("X-Auth-Token");
JSONObject headerObject = new JSONObject();
headerObject.put("contentType", contentType);
headerObject.put("token", token);
JSONObject dataObject = new JSONObject();
dataObject.put("id", UUID.randomUUID());
dataObject.put("name", name);
JSONObject resultObject = new JSONObject();
resultObject.put("datas", dataObject);
resultObject.put("header", headerObject);
return Response.ok(resultObject, MediaType.APPLICATION_JSON).status(Response.Status.OK).build();
}
Curl命令:
curl -i -H “Content-Type:application/json;charset=UTF-8” -H “X-Auth-Token:1234567876543” http://localhost:8080/simple-service-we bapp/demo/doGet?name=1234
返回结果
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: application/json
Content-Length: 151
Date: Sun, 26 May 2019 13:26:50 GMT
{"datas":{"name":"1234","id":"e899d723-e140-4d32-a59a-23fff09a82cf"},"header":{"contentType":"application/json;charset=UTF-8","token":"1234567876543"}}
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/doPost")
public Response doPost(String param, @Context HttpHeaders httpHeader, @Context UriInfo uriInfo) {
// 请求头
String contentType = httpHeader.getHeaderString("Content-Type");
String token = httpHeader.getHeaderString("X-Auth-Token");
JSONObject headerObject = new JSONObject();
headerObject.put("contentType", contentType);
headerObject.put("token", token);
JSONObject dataObject = JSONObject.parseObject(param);
JSONObject resultObject = new JSONObject();
resultObject.put("datas", dataObject);
resultObject.put("header", headerObject);
return Response.ok(resultObject, MediaType.APPLICATION_JSON).status(Response.Status.OK).build();
}
Curl命令:
curl -i -H “Content-Type:application/json;charset=UTF-8” -H “X-Auth-Token:1234567876543” -d “{“vimId”:“vim3”,“regionId”:“Reg ionOne”,“vnfrId”:“vnf1”,“operationId”:“8c500087-81bd-42fe-b227-28a3094f9f7e”,“changeType”:“scale-in”,“serverList”:[“b44a03f8-ec02-48a9-91da-cbe064b8d99b”,“bee3803b-509c-45e6-b278-43cc3614886b”,“cc3ea4de-65a4-434a-b7da-6ceb26cea1dc”],“callType”:“0”,“realEnd”:“false”}” http://localhost:8080/simple-service-webapp/demo/doPost
返回结果
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: application/json
Content-Length: 390
Date: Sun, 26 May 2019 13:30:49 GMT
{"datas":{"vimId":"vim3","regionId":"Reg ionOne","vnfrId":"vnf1","realEnd":"false","changeType":"scale-in","serverList":["b44a03f8-ec02-48a9-91da-cbe064b8d99b","bee3803b-509c-45e6-b278-43cc3614886b","cc3ea4de-65a4-434a-b7da-6ceb26cea1dc"],"operationId":"8c500087-81bd-42fe-b227-28a3094f9f7e","callType":"0"},"header":{"contentType":"application/json;charset=UTF-8","token":"1234567876543"}}