Java调用Http/Https接口(5)--HttpAsyncClient调用Http/Https接口
HttpAsyncClient是HttpClient的异步版本,提供异步调用的api。文中所使用到的软件版本:Java 1.8.0_191、HttpClient 4.1.4。
1、服务端
2、调用Http接口
2.1、GET请求
public static void get() {
String requestPath = "http://localhost:8080/demo/httptest/getUser?userId=1000&userName=李白";
CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
try {
httpClient.start();
HttpGet get = new HttpGet(requestPath);
Future<HttpResponse> future = httpClient.execute(get, null);
HttpResponse response = future.get();
System.out.println("GET返回状态:" + response.getStatusLine());
HttpEntity responseEntity = response.getEntity();
System.out.println("GET返回结果:" + EntityUtils.toString(responseEntity));
//回调方式调用
final CountDownLatch latch = new CountDownLatch(1);
final HttpGet get2 = new HttpGet(requestPath);
httpClient.execute(get2, new FutureCallback<HttpResponse>() {
public void completed(final HttpResponse response) {
latch.countDown();
System.out.println("GET(回调方式)返回状态:" + response.getStatusLine());
try {
System.out.println("GET(回调方式)返回结果:" + EntityUtils.toString(response.getEntity()));
} catch (Exception e) {
e.printStackTrace();
}
}
public void failed(final Exception e) {
latch.countDown();
e.printStackTrace();
}
public void cancelled() {
latch.countDown();
System.out.println("cancelled");
}
});
latch.await();
//流方式调用
final CountDownLatch latch2 = new CountDownLatch(1);
final HttpGet get3 = new HttpGet(requestPath);
HttpAsyncRequestProducer producer3 = HttpAsyncMethods.create(get3);
AsyncCharConsumer<HttpResponse> consumer3 = new AsyncCharConsumer<HttpResponse>() {
HttpResponse response;
@Override
protected void onResponseReceived(final HttpResponse response) {
this.response = response;
}
@Override
protected void releaseResources() {
}
@Override
protected HttpResponse buildResult(final HttpContext context) {
return this.response;
}
@Override
protected void onCharReceived(CharBuffer buf, IOControl ioctrl) throws IOException {
System.out.println("GET(流方式)返回结果:" + buf.toString());
}
};
httpClient.execute(producer3, consumer3, new FutureCallback<HttpResponse>() {
public void completed(final HttpResponse response) {
latch2.countDown();
System.out.println("GET(流方式)返回状态:" + response.getStatusLine());
}
public void failed(final Exception e) {
latch2.countDown();
e.printStackTrace();
}
public void cancelled() {
latch2.countDown();
System.out.println("cancelled");
}
});
latch2.await();
} catch (Exception e) {
e.printStackTrace();
} finally {
close(httpClient);
}
}
2.2、POST请求(发送键值对数据)
public static void post() {
CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
try {
httpClient.start();
String requestPath = "http://localhost:8080/demo/httptest/getUser";
HttpPost post = new HttpPost(requestPath);
List<NameValuePair> list = new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("userId", "1000"));
list.add(new BasicNameValuePair("userName", "李白"));
post.setEntity(new UrlEncodedFormEntity(list, "utf-8"));
Future<HttpResponse> future = httpClient.execute(post, null);
HttpResponse response = future.get();
System.out.println("POST返回状态:" + response.getStatusLine());
HttpEntity responseEntity = response.getEntity();
System.out.println("POST返回结果:" + EntityUtils.toString(responseEntity));
//回调方式和流方式调用类似
} catch (Exception e) {
e.printStackTrace();
} finally {
close(httpClient);
}
}
2.3、POST请求(发送JSON数据)
public static void post2() {
CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
try {
httpClient.start();
String requestPath = "http://localhost:8080/demo/httptest/addUser";
HttpPost post = new HttpPost(requestPath);
post.setHeader("Content-type", "application/json");
String param = "{\"userId\": \"1001\",\"userName\":\"杜甫\"}";
post.setEntity(new StringEntity(param, "utf-8"));
Future<HttpResponse> future = httpClient.execute(post, null);
HttpResponse response = future.get();
System.out.println("POST json返回状态:" + response.getStatusLine());
HttpEntity responseEntity = response.getEntity();
System.out.println("POST josn返回结果:" + EntityUtils.toString(responseEntity));
//回调方式和流方式调用类似
} catch (Exception e) {
e.printStackTrace();
} finally {
close(httpClient);
}
}
2.4、上传文件
public static void upload() {
CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
try {
httpClient.start();
String requestPath = "http://localhost:8080/demo/httptest/upload";
ZeroCopyPost producer = new ZeroCopyPost(requestPath, new File("d:/a.jpg"), ContentType.create("text/plain"));
AsyncCharConsumer<HttpResponse> consumer = new AsyncCharConsumer<HttpResponse>() {
HttpResponse response;
@Override
protected void onResponseReceived(final HttpResponse response) {
this.response = response;
}
@Override
protected void releaseResources() {
}
@Override
protected HttpResponse buildResult(final HttpContext context) {
return this.response;
}
@Override
protected void onCharReceived(CharBuffer buf, IOControl ioctrl) throws IOException {
System.out.println("upload返回结果:" + buf.toString());
}
};
Future<HttpResponse> future = httpClient.execute(producer, consumer, null);
HttpResponse response = future.get();
System.out.println("upload返回状态:" + response.getStatusLine());
} catch (Exception e) {
e.printStackTrace();
} finally {
close(httpClient);
}
}
2.5、下载文件
public static void download() {
CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
try {
httpClient.start();
String requestPath = "http://localhost:8080/demo/httptest/download";
HttpGet get = new HttpGet(requestPath);
HttpAsyncRequestProducer producer = HttpAsyncMethods.create(get);
File download = new File("d:/temp/download_" + System.currentTimeMillis() + ".jpg");
ZeroCopyConsumer<File> consumer = new ZeroCopyConsumer<File>(download) {
@Override
protected File process(final HttpResponse response, final File file, final ContentType contentType) throws Exception {
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
throw new ClientProtocolException("Upload failed: " + response.getStatusLine());
}
return file;
}
};
Future<File> future = httpClient.execute(producer, consumer, null);
System.out.println("download文件大小:" + future.get().length());
} catch (Exception e) {
e.printStackTrace();
} finally {
close(httpClient);
}
}
2.6、完整例子
package com.inspur.demo.http.client; import java.io.File;
import java.io.IOException;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future; import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
import org.apache.http.impl.nio.client.HttpAsyncClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.nio.IOControl;
import org.apache.http.nio.client.methods.AsyncCharConsumer;
import org.apache.http.nio.client.methods.HttpAsyncMethods;
import org.apache.http.nio.client.methods.ZeroCopyConsumer;
import org.apache.http.nio.client.methods.ZeroCopyPost;
import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils; /**
* 通过HttpClient调用Http接口
*/
public class HttpAsyncClientCase {
/**
* GET请求
*/
public static void get() {
String requestPath = "http://localhost:8080/demo/httptest/getUser?userId=1000&userName=李白";
CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
try {
httpClient.start();
HttpGet get = new HttpGet(requestPath);
Future<HttpResponse> future = httpClient.execute(get, null);
HttpResponse response = future.get();
System.out.println("GET返回状态:" + response.getStatusLine());
HttpEntity responseEntity = response.getEntity();
System.out.println("GET返回结果:" + EntityUtils.toString(responseEntity)); //回调方式调用
final CountDownLatch latch = new CountDownLatch(1);
final HttpGet get2 = new HttpGet(requestPath);
httpClient.execute(get2, new FutureCallback<HttpResponse>() {
public void completed(final HttpResponse response) {
latch.countDown();
System.out.println("GET(回调方式)返回状态:" + response.getStatusLine());
try {
System.out.println("GET(回调方式)返回结果:" + EntityUtils.toString(response.getEntity()));
} catch (Exception e) {
e.printStackTrace();
}
}
public void failed(final Exception e) {
latch.countDown();
e.printStackTrace();
}
public void cancelled() {
latch.countDown();
System.out.println("cancelled");
} });
latch.await(); //流方式调用
final CountDownLatch latch2 = new CountDownLatch(1);
final HttpGet get3 = new HttpGet(requestPath);
HttpAsyncRequestProducer producer3 = HttpAsyncMethods.create(get3);
AsyncCharConsumer<HttpResponse> consumer3 = new AsyncCharConsumer<HttpResponse>() {
HttpResponse response;
@Override
protected void onResponseReceived(final HttpResponse response) {
this.response = response;
}
@Override
protected void releaseResources() {
}
@Override
protected HttpResponse buildResult(final HttpContext context) {
return this.response;
}
@Override
protected void onCharReceived(CharBuffer buf, IOControl ioctrl) throws IOException {
System.out.println("GET(流方式)返回结果:" + buf.toString());
}
};
httpClient.execute(producer3, consumer3, new FutureCallback<HttpResponse>() {
public void completed(final HttpResponse response) {
latch2.countDown();
System.out.println("GET(流方式)返回状态:" + response.getStatusLine());
}
public void failed(final Exception e) {
latch2.countDown();
e.printStackTrace();
}
public void cancelled() {
latch2.countDown();
System.out.println("cancelled");
}
});
latch2.await();
} catch (Exception e) {
e.printStackTrace();
} finally {
close(httpClient);
}
} /**
* POST请求(发送键值对数据)
*/
public static void post() {
CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
try {
httpClient.start();
String requestPath = "http://localhost:8080/demo/httptest/getUser";
HttpPost post = new HttpPost(requestPath); List<NameValuePair> list = new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("userId", "1000"));
list.add(new BasicNameValuePair("userName", "李白"));
post.setEntity(new UrlEncodedFormEntity(list, "utf-8")); Future<HttpResponse> future = httpClient.execute(post, null);
HttpResponse response = future.get();
System.out.println("POST返回状态:" + response.getStatusLine());
HttpEntity responseEntity = response.getEntity();
System.out.println("POST返回结果:" + EntityUtils.toString(responseEntity)); //回调方式和流方式调用类似
} catch (Exception e) {
e.printStackTrace();
} finally {
close(httpClient);
}
} /**
* POST请求(发送json数据)
*/
public static void post2() {
CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
try {
httpClient.start();
String requestPath = "http://localhost:8080/demo/httptest/addUser";
HttpPost post = new HttpPost(requestPath);
post.setHeader("Content-type", "application/json");
String param = "{\"userId\": \"1001\",\"userName\":\"杜甫\"}";
post.setEntity(new StringEntity(param, "utf-8")); Future<HttpResponse> future = httpClient.execute(post, null);
HttpResponse response = future.get();
System.out.println("POST json返回状态:" + response.getStatusLine());
HttpEntity responseEntity = response.getEntity();
System.out.println("POST josn返回结果:" + EntityUtils.toString(responseEntity)); //回调方式和流方式调用类似
} catch (Exception e) {
e.printStackTrace();
} finally {
close(httpClient);
}
} /**
* 上传文件
*/
public static void upload() {
CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
try {
httpClient.start();
String requestPath = "http://localhost:8080/demo/httptest/upload";
ZeroCopyPost producer = new ZeroCopyPost(requestPath, new File("d:/a.jpg"), ContentType.create("text/plain"));
AsyncCharConsumer<HttpResponse> consumer = new AsyncCharConsumer<HttpResponse>() {
HttpResponse response;
@Override
protected void onResponseReceived(final HttpResponse response) {
this.response = response;
}
@Override
protected void releaseResources() {
}
@Override
protected HttpResponse buildResult(final HttpContext context) {
return this.response;
}
@Override
protected void onCharReceived(CharBuffer buf, IOControl ioctrl) throws IOException {
System.out.println("upload返回结果:" + buf.toString());
}
};
Future<HttpResponse> future = httpClient.execute(producer, consumer, null);
HttpResponse response = future.get();
System.out.println("upload返回状态:" + response.getStatusLine());
} catch (Exception e) {
e.printStackTrace();
} finally {
close(httpClient);
}
} /**
* 下载文件
*/
public static void download() {
CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
try {
httpClient.start();
String requestPath = "http://localhost:8080/demo/httptest/download";
HttpGet get = new HttpGet(requestPath);
HttpAsyncRequestProducer producer = HttpAsyncMethods.create(get);
File download = new File("d:/temp/download_" + System.currentTimeMillis() + ".jpg");
ZeroCopyConsumer<File> consumer = new ZeroCopyConsumer<File>(download) {
@Override
protected File process(final HttpResponse response, final File file, final ContentType contentType) throws Exception {
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
throw new ClientProtocolException("Upload failed: " + response.getStatusLine());
}
return file;
}
};
Future<File> future = httpClient.execute(producer, consumer, null);
System.out.println("download文件大小:" + future.get().length());
} catch (Exception e) {
e.printStackTrace();
} finally {
close(httpClient);
}
} private static void close(CloseableHttpAsyncClient httpClient) {
try {
if (httpClient != null) {
httpClient.close();
}
} catch (IOException e) {
e.printStackTrace();
}
} public static void main(String[] args) {
get();
post();
post2();
upload();
download();
}
}
3、调用Https接口
与调用Http接口不一样的部分主要在设置ssl部分,其ssl的设置与HttpsURLConnection很相似(参见Java调用Http/Https接口(2)--HttpURLConnection/HttpsURLConnection调用Http/Https接口);下面用GET请求来演示ssl的设置,其他调用方式类似。
package com.inspur.demo.http.client; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.KeyStore;
import java.util.concurrent.Future; import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession; import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
import org.apache.http.impl.nio.client.HttpAsyncClients;
import org.apache.http.nio.conn.ssl.SSLIOSessionStrategy;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.util.EntityUtils; import com.inspur.demo.common.util.FileUtil; /**
* 通过HttpAsyncClient调用Https接口
*/
public class HttpAsyncClientHttpsCase { public static void main(String[] args) {
CloseableHttpAsyncClient httpAsyncClient = null;
CloseableHttpAsyncClient httpAsyncClient2 = null;
CloseableHttpAsyncClient httpAsyncClient3 = null;
try {
/*
* 请求有权威证书的地址
*/
String requestPath = "https://www.12306.cn/index/";
httpAsyncClient = HttpAsyncClients.createDefault();
httpAsyncClient.start();
HttpGet get = new HttpGet(requestPath);
Future<HttpResponse> future = httpAsyncClient.execute(get, null);
HttpResponse response = future.get();
System.out.println(response.getStatusLine());
System.out.println("GET1返回结果:" + EntityUtils.toString(response.getEntity(), "utf-8")); /*
* 请求自定义证书的地址
*/
//获取信任证书库
KeyStore trustStore = getkeyStore("jks", "d:/temp/cacerts", "123456");
//不需要客户端证书
requestPath = "https://10.40.x.x:9010/zsywservice";
httpAsyncClient2 = HttpAsyncClients.custom().setSSLStrategy(getSSLIOSessionStrategy(trustStore)).build();
httpAsyncClient2.start();
get = new HttpGet(requestPath);
future = httpAsyncClient2.execute(get, null);
response = future.get();
System.out.println("GET2:" + EntityUtils.toString(response.getEntity())); //需要客户端证书
requestPath = "https://10.40.x.x:9016/zsywservice";
KeyStore keyStore = getkeyStore("pkcs12", "d:/client.p12", "123456");
httpAsyncClient3 = HttpAsyncClients.custom().setSSLStrategy(getSSLIOSessionStrategy(keyStore, "123456", trustStore)).build();
httpAsyncClient3.start();
get = new HttpGet(requestPath);
future = httpAsyncClient3.execute(get, null);
response = future.get();
System.out.println("GET3返回结果:" + EntityUtils.toString(response.getEntity()));
} catch (Exception e) {
e.printStackTrace();
} finally {
close(httpAsyncClient);
close(httpAsyncClient2);
close(httpAsyncClient3);
}
} public static SSLIOSessionStrategy getSSLIOSessionStrategy(KeyStore keyStore, String keyPassword, KeyStore trustStore) throws Exception {
SSLContextBuilder bulider = SSLContexts.custom();
if (keyStore != null) {
bulider.loadKeyMaterial(keyStore, keyPassword.toCharArray());
}
if (keyStore != null) {
bulider.loadTrustMaterial(trustStore, null);
} else {
bulider.loadTrustMaterial(new TrustSelfSignedStrategy());
}
SSLContext sslContext = bulider.build();
// 验证URL的主机名和服务器的标识主机名是否匹配
HostnameVerifier hostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
// if ("xxx".equals(hostname)) {
// return true;
// } else {
// return false;
// }
return true;
}
};
SSLIOSessionStrategy strategy = new SSLIOSessionStrategy(sslContext, new String[] { "TLSv1", "TLSv1.2" }, null,
hostnameVerifier); return strategy;
} public static SSLIOSessionStrategy getSSLIOSessionStrategy(KeyStore trustStore) throws Exception {
return getSSLIOSessionStrategy(null, null, trustStore);
} private static KeyStore getkeyStore(String type, String filePath, String password) {
KeyStore keySotre = null;
FileInputStream in = null;
try {
keySotre = KeyStore.getInstance(type);
in = new FileInputStream(new File(filePath));
keySotre.load(in, password.toCharArray());
} catch (Exception e) {
e.printStackTrace();
} finally {
FileUtil.close(in);
}
return keySotre;
} private static void close(CloseableHttpAsyncClient httpClient) {
try {
if (httpClient != null) {
httpClient.close();
}
} catch (IOException e) {
e.printStackTrace();
}
} }
Java调用Http/Https接口(5)--HttpAsyncClient调用Http/Https接口的更多相关文章
- Java WebService接口生成和调用 图文详解>【转】【待调整】
webservice简介: Web Service技术, 能使得运行在不同机器上的不同应用无须借助附加的.专门的第三方软件或硬件, 就可相互交换数据或集成.依据Web Service规范实施的应用之间 ...
- c#代码 天气接口 一分钟搞懂你的博客为什么没人看 看完python这段爬虫代码,java流泪了c#沉默了 图片二进制转换与存入数据库相关 C#7.0--引用返回值和引用局部变量 JS直接调用C#后台方法(ajax调用) Linq To Json SqlServer 递归查询
天气预报的程序.程序并不难. 看到这个需求第一个想法就是只要找到合适天气预报接口一切都是小意思,说干就干,立马跟学生沟通价格. 不过谈报价的过程中,差点没让我一口老血喷键盘上,话说我们程序猿的人 ...
- java接口对接——别人调用我们接口获取数据
java接口对接——别人调用我们接口获取数据,我们需要在我们系统中开发几个接口,给对方接口规范文档,包括访问我们的接口地址,以及入参名称和格式,还有我们的返回的状态的情况, 接口代码: package ...
- .net WebServer示例及调用(接口WSDL动态调用 JAVA)
新建.asmx页面 using System; using System.Collections.Generic; using System.Linq; using System.Web; using ...
- 使用Socket&反射&Java流操作进行方法的远程调用(模拟RPC远程调用)
写在前面 阅读本文首先得具备基本的Socket.反射.Java流操作的基本API使用知识:否则本文你可能看不懂... 服务端的端口监听 进行远程调用,那就必须得有客户端和服务端.服务端负责提供服务,客 ...
- java多态的实现原理(JVM调用过程)(综合多篇文章,参考见文末)
一个对象变量可以指示多种实际类型的现象称为多态 允许不同类的对象对同一消息做出响应.方法的重载.类的覆盖正体现了多态. 1.多态的机制 1.1 本质上多态分两种 1.编译时多态(又称静态多态) 2.运 ...
- 从Java future 到 Guava ListenableFuture实现异步调用
从Java future 到 Guava ListenableFuture实现异步调用 置顶 2016年04月24日 09:11:14 皮斯特劳沃 阅读数:17570 标签: java异步调用线程非阻 ...
- Atitit java c# php c++ js跨语言调用matlab实现边缘检测等功能attilax总结
Atitit java c# php c++ js跨语言调用matlab实现边缘检测等功能attilax总结 1.1. 边缘检测的基本方法Canny最常用了1 1.2. 编写matlab边缘检测代码, ...
- 【Java EE 学习 80 下】【调用WebService服务的四种方式】【WebService中的注解】
不考虑第三方框架,如果只使用JDK提供的API,那么可以使用三种方式调用WebService服务:另外还可以使用Ajax调用WebService服务. 预备工作:开启WebService服务,使用jd ...
随机推荐
- 访问者模式(Visitor Patten)
参考文章: http://www.importnew.com/15561.html 定义: 封装某些作用于某种数据结构中各元素的操作,它可以在不改变数据结构的前提下定义作用于这些元素的新的操作. um ...
- 第1001次安kali
第1001次安kali 由于VMware跟win10有仇等原因,最终投入了VirtualBox的怀抱 主要参考这个博客Kali Linux安装教程--VirtualBox 参考Kali安装教程(Vir ...
- 完全卸载Oracle(亲身体验完整版)
完全卸载Oracle 用Oracle自带的卸载程序不能从根本上卸载Oracle,从而为下次的安装留下隐患,那么怎么才能完全卸载Oracle呢? 那就是直接注册表清除,步骤如下: 开始->设置-& ...
- jdk8 stream实现sql单表select a,b,sum(),avg(),max() from group by a,b order by a,b limit M offset N及其性能
之所以要测该场景,是因为merge多数据源结果的时候,有时候只是单个子查询结果了,而此时采用sql数据库处理并不一定能够合理(网络延迟太大). 测试数据10万行,结果1000行 limit 20 of ...
- cmd find命令用法
Windows命令行(cmd)下快速查找文件(类似Linux下find命令) 2015年04月11日 10:50:43 开水 阅读数 62240 标签: 命令行cmdwindows 更多 个人分类: ...
- python开源项目聚合推荐【1】
******************************************************* 01项目名:unimatrix 功能介绍:Python模拟“黑客帝国”影片中的终端动画脚 ...
- python初级(302) 5 列表
一.复习 1.函数的创建 1) def关键字 2) 函数名及后面跟随的括号 3)冒号加上函数体 2.函数的调用 函数名及后面跟随的括号 3.带一个,二个,三个参数的函数及调用 二.列表 family ...
- iOS - 获取系统时间年月日,阳历(公历)日期转农历的方法
//获取当前时间 NSDate *now = [NSDate date]; NSLog(@" now date is: %@ ",now); NSCalendar *calenda ...
- 【bat批处理】批量执行某个文件夹下的所有sql文件bat批处理
遍历文件夹下所有的sql文件,然后命令行执行 for /r "D:\yonyou\UBFV60\U9.VOB.Product.Other" %%a in (*.sql) do ( ...
- [Linux] cronjob指定用户运行脚本,并按日期区分输出日志
废话不多说,直接上代码,在root的cronjob,指定nginx用户跑cronjob */1 * * * * su nginx -c "/usr/local/scripts/goods.s ...