HttpAsyncClient是HttpClient的异步版本,提供异步调用的api。文中所使用到的软件版本:Java 1.8.0_191、HttpClient 4.1.4。

1、服务端

参见Java调用Http接口(1)--编写服务端

2、调用Http接口

2.1、GET请求

  1. public static void get() {
  2. String requestPath = "http://localhost:8080/demo/httptest/getUser?userId=1000&userName=李白";
  3. CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
  4. try {
  5. httpClient.start();
  6. HttpGet get = new HttpGet(requestPath);
  7. Future<HttpResponse> future = httpClient.execute(get, null);
  8. HttpResponse response = future.get();
  9. System.out.println("GET返回状态:" + response.getStatusLine());
  10. HttpEntity responseEntity = response.getEntity();
  11. System.out.println("GET返回结果:" + EntityUtils.toString(responseEntity));
  12.  
  13. //回调方式调用
  14. final CountDownLatch latch = new CountDownLatch(1);
  15. final HttpGet get2 = new HttpGet(requestPath);
  16. httpClient.execute(get2, new FutureCallback<HttpResponse>() {
  17. public void completed(final HttpResponse response) {
  18. latch.countDown();
  19. System.out.println("GET(回调方式)返回状态:" + response.getStatusLine());
  20. try {
  21. System.out.println("GET(回调方式)返回结果:" + EntityUtils.toString(response.getEntity()));
  22. } catch (Exception e) {
  23. e.printStackTrace();
  24. }
  25. }
  26. public void failed(final Exception e) {
  27. latch.countDown();
  28. e.printStackTrace();
  29. }
  30. public void cancelled() {
  31. latch.countDown();
  32. System.out.println("cancelled");
  33. }
  34.  
  35. });
  36. latch.await();
  37.  
  38. //流方式调用
  39. final CountDownLatch latch2 = new CountDownLatch(1);
  40. final HttpGet get3 = new HttpGet(requestPath);
  41. HttpAsyncRequestProducer producer3 = HttpAsyncMethods.create(get3);
  42. AsyncCharConsumer<HttpResponse> consumer3 = new AsyncCharConsumer<HttpResponse>() {
  43. HttpResponse response;
  44. @Override
  45. protected void onResponseReceived(final HttpResponse response) {
  46. this.response = response;
  47. }
  48. @Override
  49. protected void releaseResources() {
  50. }
  51. @Override
  52. protected HttpResponse buildResult(final HttpContext context) {
  53. return this.response;
  54. }
  55. @Override
  56. protected void onCharReceived(CharBuffer buf, IOControl ioctrl) throws IOException {
  57. System.out.println("GET(流方式)返回结果:" + buf.toString());
  58. }
  59. };
  60. httpClient.execute(producer3, consumer3, new FutureCallback<HttpResponse>() {
  61. public void completed(final HttpResponse response) {
  62. latch2.countDown();
  63. System.out.println("GET(流方式)返回状态:" + response.getStatusLine());
  64. }
  65. public void failed(final Exception e) {
  66. latch2.countDown();
  67. e.printStackTrace();
  68. }
  69. public void cancelled() {
  70. latch2.countDown();
  71. System.out.println("cancelled");
  72. }
  73. });
  74. latch2.await();
  75. } catch (Exception e) {
  76. e.printStackTrace();
  77. } finally {
  78. close(httpClient);
  79. }
  80. }

2.2、POST请求(发送键值对数据)

  1. public static void post() {
  2. CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
  3. try {
  4. httpClient.start();
  5. String requestPath = "http://localhost:8080/demo/httptest/getUser";
  6. HttpPost post = new HttpPost(requestPath);
  7.  
  8. List<NameValuePair> list = new ArrayList<NameValuePair>();
  9. list.add(new BasicNameValuePair("userId", "1000"));
  10. list.add(new BasicNameValuePair("userName", "李白"));
  11. post.setEntity(new UrlEncodedFormEntity(list, "utf-8"));
  12.  
  13. Future<HttpResponse> future = httpClient.execute(post, null);
  14. HttpResponse response = future.get();
  15. System.out.println("POST返回状态:" + response.getStatusLine());
  16. HttpEntity responseEntity = response.getEntity();
  17. System.out.println("POST返回结果:" + EntityUtils.toString(responseEntity));
  18.  
  19. //回调方式和流方式调用类似
  20. } catch (Exception e) {
  21. e.printStackTrace();
  22. } finally {
  23. close(httpClient);
  24. }
  25. }

2.3、POST请求(发送JSON数据)

  1. public static void post2() {
  2. CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
  3. try {
  4. httpClient.start();
  5. String requestPath = "http://localhost:8080/demo/httptest/addUser";
  6. HttpPost post = new HttpPost(requestPath);
  7. post.setHeader("Content-type", "application/json");
  8. String param = "{\"userId\": \"1001\",\"userName\":\"杜甫\"}";
  9. post.setEntity(new StringEntity(param, "utf-8"));
  10.  
  11. Future<HttpResponse> future = httpClient.execute(post, null);
  12. HttpResponse response = future.get();
  13. System.out.println("POST json返回状态:" + response.getStatusLine());
  14. HttpEntity responseEntity = response.getEntity();
  15. System.out.println("POST josn返回结果:" + EntityUtils.toString(responseEntity));
  16.  
  17. //回调方式和流方式调用类似
  18. } catch (Exception e) {
  19. e.printStackTrace();
  20. } finally {
  21. close(httpClient);
  22. }
  23. }

2.4、上传文件

  1. public static void upload() {
  2. CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
  3. try {
  4. httpClient.start();
  5. String requestPath = "http://localhost:8080/demo/httptest/upload";
  6. ZeroCopyPost producer = new ZeroCopyPost(requestPath, new File("d:/a.jpg"), ContentType.create("text/plain"));
  7. AsyncCharConsumer<HttpResponse> consumer = new AsyncCharConsumer<HttpResponse>() {
  8. HttpResponse response;
  9. @Override
  10. protected void onResponseReceived(final HttpResponse response) {
  11. this.response = response;
  12. }
  13. @Override
  14. protected void releaseResources() {
  15. }
  16. @Override
  17. protected HttpResponse buildResult(final HttpContext context) {
  18. return this.response;
  19. }
  20. @Override
  21. protected void onCharReceived(CharBuffer buf, IOControl ioctrl) throws IOException {
  22. System.out.println("upload返回结果:" + buf.toString());
  23. }
  24. };
  25. Future<HttpResponse> future = httpClient.execute(producer, consumer, null);
  26. HttpResponse response = future.get();
  27. System.out.println("upload返回状态:" + response.getStatusLine());
  28. } catch (Exception e) {
  29. e.printStackTrace();
  30. } finally {
  31. close(httpClient);
  32. }
  33. }

2.5、下载文件

  1. public static void download() {
  2. CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
  3. try {
  4. httpClient.start();
  5. String requestPath = "http://localhost:8080/demo/httptest/download";
  6. HttpGet get = new HttpGet(requestPath);
  7. HttpAsyncRequestProducer producer = HttpAsyncMethods.create(get);
  8. File download = new File("d:/temp/download_" + System.currentTimeMillis() + ".jpg");
  9. ZeroCopyConsumer<File> consumer = new ZeroCopyConsumer<File>(download) {
  10. @Override
  11. protected File process(final HttpResponse response, final File file, final ContentType contentType) throws Exception {
  12. if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
  13. throw new ClientProtocolException("Upload failed: " + response.getStatusLine());
  14. }
  15. return file;
  16. }
  17. };
  18. Future<File> future = httpClient.execute(producer, consumer, null);
  19. System.out.println("download文件大小:" + future.get().length());
  20. } catch (Exception e) {
  21. e.printStackTrace();
  22. } finally {
  23. close(httpClient);
  24. }
  25. }

2.6、完整例子

  1. package com.inspur.demo.http.client;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.nio.CharBuffer;
  6. import java.util.ArrayList;
  7. import java.util.List;
  8. import java.util.concurrent.CountDownLatch;
  9. import java.util.concurrent.Future;
  10.  
  11. import org.apache.http.HttpEntity;
  12. import org.apache.http.HttpResponse;
  13. import org.apache.http.HttpStatus;
  14. import org.apache.http.NameValuePair;
  15. import org.apache.http.client.ClientProtocolException;
  16. import org.apache.http.client.entity.UrlEncodedFormEntity;
  17. import org.apache.http.client.methods.HttpGet;
  18. import org.apache.http.client.methods.HttpPost;
  19. import org.apache.http.concurrent.FutureCallback;
  20. import org.apache.http.entity.ContentType;
  21. import org.apache.http.entity.StringEntity;
  22. import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
  23. import org.apache.http.impl.nio.client.HttpAsyncClients;
  24. import org.apache.http.message.BasicNameValuePair;
  25. import org.apache.http.nio.IOControl;
  26. import org.apache.http.nio.client.methods.AsyncCharConsumer;
  27. import org.apache.http.nio.client.methods.HttpAsyncMethods;
  28. import org.apache.http.nio.client.methods.ZeroCopyConsumer;
  29. import org.apache.http.nio.client.methods.ZeroCopyPost;
  30. import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
  31. import org.apache.http.protocol.HttpContext;
  32. import org.apache.http.util.EntityUtils;
  33.  
  34. /**
  35. * 通过HttpClient调用Http接口
  36. */
  37. public class HttpAsyncClientCase {
  38. /**
  39. * GET请求
  40. */
  41. public static void get() {
  42. String requestPath = "http://localhost:8080/demo/httptest/getUser?userId=1000&userName=李白";
  43. CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
  44. try {
  45. httpClient.start();
  46. HttpGet get = new HttpGet(requestPath);
  47. Future<HttpResponse> future = httpClient.execute(get, null);
  48. HttpResponse response = future.get();
  49. System.out.println("GET返回状态:" + response.getStatusLine());
  50. HttpEntity responseEntity = response.getEntity();
  51. System.out.println("GET返回结果:" + EntityUtils.toString(responseEntity));
  52.  
  53. //回调方式调用
  54. final CountDownLatch latch = new CountDownLatch(1);
  55. final HttpGet get2 = new HttpGet(requestPath);
  56. httpClient.execute(get2, new FutureCallback<HttpResponse>() {
  57. public void completed(final HttpResponse response) {
  58. latch.countDown();
  59. System.out.println("GET(回调方式)返回状态:" + response.getStatusLine());
  60. try {
  61. System.out.println("GET(回调方式)返回结果:" + EntityUtils.toString(response.getEntity()));
  62. } catch (Exception e) {
  63. e.printStackTrace();
  64. }
  65. }
  66. public void failed(final Exception e) {
  67. latch.countDown();
  68. e.printStackTrace();
  69. }
  70. public void cancelled() {
  71. latch.countDown();
  72. System.out.println("cancelled");
  73. }
  74.  
  75. });
  76. latch.await();
  77.  
  78. //流方式调用
  79. final CountDownLatch latch2 = new CountDownLatch(1);
  80. final HttpGet get3 = new HttpGet(requestPath);
  81. HttpAsyncRequestProducer producer3 = HttpAsyncMethods.create(get3);
  82. AsyncCharConsumer<HttpResponse> consumer3 = new AsyncCharConsumer<HttpResponse>() {
  83. HttpResponse response;
  84. @Override
  85. protected void onResponseReceived(final HttpResponse response) {
  86. this.response = response;
  87. }
  88. @Override
  89. protected void releaseResources() {
  90. }
  91. @Override
  92. protected HttpResponse buildResult(final HttpContext context) {
  93. return this.response;
  94. }
  95. @Override
  96. protected void onCharReceived(CharBuffer buf, IOControl ioctrl) throws IOException {
  97. System.out.println("GET(流方式)返回结果:" + buf.toString());
  98. }
  99. };
  100. httpClient.execute(producer3, consumer3, new FutureCallback<HttpResponse>() {
  101. public void completed(final HttpResponse response) {
  102. latch2.countDown();
  103. System.out.println("GET(流方式)返回状态:" + response.getStatusLine());
  104. }
  105. public void failed(final Exception e) {
  106. latch2.countDown();
  107. e.printStackTrace();
  108. }
  109. public void cancelled() {
  110. latch2.countDown();
  111. System.out.println("cancelled");
  112. }
  113. });
  114. latch2.await();
  115. } catch (Exception e) {
  116. e.printStackTrace();
  117. } finally {
  118. close(httpClient);
  119. }
  120. }
  121.  
  122. /**
  123. * POST请求(发送键值对数据)
  124. */
  125. public static void post() {
  126. CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
  127. try {
  128. httpClient.start();
  129. String requestPath = "http://localhost:8080/demo/httptest/getUser";
  130. HttpPost post = new HttpPost(requestPath);
  131.  
  132. List<NameValuePair> list = new ArrayList<NameValuePair>();
  133. list.add(new BasicNameValuePair("userId", "1000"));
  134. list.add(new BasicNameValuePair("userName", "李白"));
  135. post.setEntity(new UrlEncodedFormEntity(list, "utf-8"));
  136.  
  137. Future<HttpResponse> future = httpClient.execute(post, null);
  138. HttpResponse response = future.get();
  139. System.out.println("POST返回状态:" + response.getStatusLine());
  140. HttpEntity responseEntity = response.getEntity();
  141. System.out.println("POST返回结果:" + EntityUtils.toString(responseEntity));
  142.  
  143. //回调方式和流方式调用类似
  144. } catch (Exception e) {
  145. e.printStackTrace();
  146. } finally {
  147. close(httpClient);
  148. }
  149. }
  150.  
  151. /**
  152. * POST请求(发送json数据)
  153. */
  154. public static void post2() {
  155. CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
  156. try {
  157. httpClient.start();
  158. String requestPath = "http://localhost:8080/demo/httptest/addUser";
  159. HttpPost post = new HttpPost(requestPath);
  160. post.setHeader("Content-type", "application/json");
  161. String param = "{\"userId\": \"1001\",\"userName\":\"杜甫\"}";
  162. post.setEntity(new StringEntity(param, "utf-8"));
  163.  
  164. Future<HttpResponse> future = httpClient.execute(post, null);
  165. HttpResponse response = future.get();
  166. System.out.println("POST json返回状态:" + response.getStatusLine());
  167. HttpEntity responseEntity = response.getEntity();
  168. System.out.println("POST josn返回结果:" + EntityUtils.toString(responseEntity));
  169.  
  170. //回调方式和流方式调用类似
  171. } catch (Exception e) {
  172. e.printStackTrace();
  173. } finally {
  174. close(httpClient);
  175. }
  176. }
  177.  
  178. /**
  179. * 上传文件
  180. */
  181. public static void upload() {
  182. CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
  183. try {
  184. httpClient.start();
  185. String requestPath = "http://localhost:8080/demo/httptest/upload";
  186. ZeroCopyPost producer = new ZeroCopyPost(requestPath, new File("d:/a.jpg"), ContentType.create("text/plain"));
  187. AsyncCharConsumer<HttpResponse> consumer = new AsyncCharConsumer<HttpResponse>() {
  188. HttpResponse response;
  189. @Override
  190. protected void onResponseReceived(final HttpResponse response) {
  191. this.response = response;
  192. }
  193. @Override
  194. protected void releaseResources() {
  195. }
  196. @Override
  197. protected HttpResponse buildResult(final HttpContext context) {
  198. return this.response;
  199. }
  200. @Override
  201. protected void onCharReceived(CharBuffer buf, IOControl ioctrl) throws IOException {
  202. System.out.println("upload返回结果:" + buf.toString());
  203. }
  204. };
  205. Future<HttpResponse> future = httpClient.execute(producer, consumer, null);
  206. HttpResponse response = future.get();
  207. System.out.println("upload返回状态:" + response.getStatusLine());
  208. } catch (Exception e) {
  209. e.printStackTrace();
  210. } finally {
  211. close(httpClient);
  212. }
  213. }
  214.  
  215. /**
  216. * 下载文件
  217. */
  218. public static void download() {
  219. CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
  220. try {
  221. httpClient.start();
  222. String requestPath = "http://localhost:8080/demo/httptest/download";
  223. HttpGet get = new HttpGet(requestPath);
  224. HttpAsyncRequestProducer producer = HttpAsyncMethods.create(get);
  225. File download = new File("d:/temp/download_" + System.currentTimeMillis() + ".jpg");
  226. ZeroCopyConsumer<File> consumer = new ZeroCopyConsumer<File>(download) {
  227. @Override
  228. protected File process(final HttpResponse response, final File file, final ContentType contentType) throws Exception {
  229. if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
  230. throw new ClientProtocolException("Upload failed: " + response.getStatusLine());
  231. }
  232. return file;
  233. }
  234. };
  235. Future<File> future = httpClient.execute(producer, consumer, null);
  236. System.out.println("download文件大小:" + future.get().length());
  237. } catch (Exception e) {
  238. e.printStackTrace();
  239. } finally {
  240. close(httpClient);
  241. }
  242. }
  243.  
  244. private static void close(CloseableHttpAsyncClient httpClient) {
  245. try {
  246. if (httpClient != null) {
  247. httpClient.close();
  248. }
  249. } catch (IOException e) {
  250. e.printStackTrace();
  251. }
  252. }
  253.  
  254. public static void main(String[] args) {
  255. get();
  256. post();
  257. post2();
  258. upload();
  259. download();
  260. }
  261. }

3、调用Https接口

与调用Http接口不一样的部分主要在设置ssl部分,其ssl的设置与HttpsURLConnection很相似(参见Java调用Http/Https接口(2)--HttpURLConnection/HttpsURLConnection调用Http/Https接口);下面用GET请求来演示ssl的设置,其他调用方式类似。

  1. package com.inspur.demo.http.client;
  2.  
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.IOException;
  6. import java.security.KeyStore;
  7. import java.util.concurrent.Future;
  8.  
  9. import javax.net.ssl.HostnameVerifier;
  10. import javax.net.ssl.SSLContext;
  11. import javax.net.ssl.SSLSession;
  12.  
  13. import org.apache.http.HttpResponse;
  14. import org.apache.http.client.methods.HttpGet;
  15. import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
  16. import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
  17. import org.apache.http.impl.nio.client.HttpAsyncClients;
  18. import org.apache.http.nio.conn.ssl.SSLIOSessionStrategy;
  19. import org.apache.http.ssl.SSLContextBuilder;
  20. import org.apache.http.ssl.SSLContexts;
  21. import org.apache.http.util.EntityUtils;
  22.  
  23. import com.inspur.demo.common.util.FileUtil;
  24.  
  25. /**
  26. * 通过HttpAsyncClient调用Https接口
  27. */
  28. public class HttpAsyncClientHttpsCase {
  29.  
  30. public static void main(String[] args) {
  31. CloseableHttpAsyncClient httpAsyncClient = null;
  32. CloseableHttpAsyncClient httpAsyncClient2 = null;
  33. CloseableHttpAsyncClient httpAsyncClient3 = null;
  34. try {
  35. /*
  36. * 请求有权威证书的地址
  37. */
  38. String requestPath = "https://www.12306.cn/index/";
  39. httpAsyncClient = HttpAsyncClients.createDefault();
  40. httpAsyncClient.start();
  41. HttpGet get = new HttpGet(requestPath);
  42. Future<HttpResponse> future = httpAsyncClient.execute(get, null);
  43. HttpResponse response = future.get();
  44. System.out.println(response.getStatusLine());
  45. System.out.println("GET1返回结果:" + EntityUtils.toString(response.getEntity(), "utf-8"));
  46.  
  47. /*
  48. * 请求自定义证书的地址
  49. */
  50. //获取信任证书库
  51. KeyStore trustStore = getkeyStore("jks", "d:/temp/cacerts", "123456");
  52. //不需要客户端证书
  53. requestPath = "https://10.40.x.x:9010/zsywservice";
  54. httpAsyncClient2 = HttpAsyncClients.custom().setSSLStrategy(getSSLIOSessionStrategy(trustStore)).build();
  55. httpAsyncClient2.start();
  56. get = new HttpGet(requestPath);
  57. future = httpAsyncClient2.execute(get, null);
  58. response = future.get();
  59. System.out.println("GET2:" + EntityUtils.toString(response.getEntity()));
  60.  
  61. //需要客户端证书
  62. requestPath = "https://10.40.x.x:9016/zsywservice";
  63. KeyStore keyStore = getkeyStore("pkcs12", "d:/client.p12", "123456");
  64. httpAsyncClient3 = HttpAsyncClients.custom().setSSLStrategy(getSSLIOSessionStrategy(keyStore, "123456", trustStore)).build();
  65. httpAsyncClient3.start();
  66. get = new HttpGet(requestPath);
  67. future = httpAsyncClient3.execute(get, null);
  68. response = future.get();
  69. System.out.println("GET3返回结果:" + EntityUtils.toString(response.getEntity()));
  70. } catch (Exception e) {
  71. e.printStackTrace();
  72. } finally {
  73. close(httpAsyncClient);
  74. close(httpAsyncClient2);
  75. close(httpAsyncClient3);
  76. }
  77. }
  78.  
  79. public static SSLIOSessionStrategy getSSLIOSessionStrategy(KeyStore keyStore, String keyPassword, KeyStore trustStore) throws Exception {
  80. SSLContextBuilder bulider = SSLContexts.custom();
  81. if (keyStore != null) {
  82. bulider.loadKeyMaterial(keyStore, keyPassword.toCharArray());
  83. }
  84. if (keyStore != null) {
  85. bulider.loadTrustMaterial(trustStore, null);
  86. } else {
  87. bulider.loadTrustMaterial(new TrustSelfSignedStrategy());
  88. }
  89. SSLContext sslContext = bulider.build();
  90. // 验证URL的主机名和服务器的标识主机名是否匹配
  91. HostnameVerifier hostnameVerifier = new HostnameVerifier() {
  92. @Override
  93. public boolean verify(String hostname, SSLSession session) {
  94. // if ("xxx".equals(hostname)) {
  95. // return true;
  96. // } else {
  97. // return false;
  98. // }
  99. return true;
  100. }
  101. };
  102. SSLIOSessionStrategy strategy = new SSLIOSessionStrategy(sslContext, new String[] { "TLSv1", "TLSv1.2" }, null,
  103. hostnameVerifier);
  104.  
  105. return strategy;
  106. }
  107.  
  108. public static SSLIOSessionStrategy getSSLIOSessionStrategy(KeyStore trustStore) throws Exception {
  109. return getSSLIOSessionStrategy(null, null, trustStore);
  110. }
  111.  
  112. private static KeyStore getkeyStore(String type, String filePath, String password) {
  113. KeyStore keySotre = null;
  114. FileInputStream in = null;
  115. try {
  116. keySotre = KeyStore.getInstance(type);
  117. in = new FileInputStream(new File(filePath));
  118. keySotre.load(in, password.toCharArray());
  119. } catch (Exception e) {
  120. e.printStackTrace();
  121. } finally {
  122. FileUtil.close(in);
  123. }
  124. return keySotre;
  125. }
  126.  
  127. private static void close(CloseableHttpAsyncClient httpClient) {
  128. try {
  129. if (httpClient != null) {
  130. httpClient.close();
  131. }
  132. } catch (IOException e) {
  133. e.printStackTrace();
  134. }
  135. }
  136.  
  137. }

Java调用Http/Https接口(5)--HttpAsyncClient调用Http/Https接口的更多相关文章

  1. Java WebService接口生成和调用 图文详解>【转】【待调整】

    webservice简介: Web Service技术, 能使得运行在不同机器上的不同应用无须借助附加的.专门的第三方软件或硬件, 就可相互交换数据或集成.依据Web Service规范实施的应用之间 ...

  2. c#代码 天气接口 一分钟搞懂你的博客为什么没人看 看完python这段爬虫代码,java流泪了c#沉默了 图片二进制转换与存入数据库相关 C#7.0--引用返回值和引用局部变量 JS直接调用C#后台方法(ajax调用) Linq To Json SqlServer 递归查询

    天气预报的程序.程序并不难. 看到这个需求第一个想法就是只要找到合适天气预报接口一切都是小意思,说干就干,立马跟学生沟通价格. ​ ​不过谈报价的过程中,差点没让我一口老血喷键盘上,话说我们程序猿的人 ...

  3. java接口对接——别人调用我们接口获取数据

    java接口对接——别人调用我们接口获取数据,我们需要在我们系统中开发几个接口,给对方接口规范文档,包括访问我们的接口地址,以及入参名称和格式,还有我们的返回的状态的情况, 接口代码: package ...

  4. .net WebServer示例及调用(接口WSDL动态调用 JAVA)

    新建.asmx页面 using System; using System.Collections.Generic; using System.Linq; using System.Web; using ...

  5. 使用Socket&反射&Java流操作进行方法的远程调用(模拟RPC远程调用)

    写在前面 阅读本文首先得具备基本的Socket.反射.Java流操作的基本API使用知识:否则本文你可能看不懂... 服务端的端口监听 进行远程调用,那就必须得有客户端和服务端.服务端负责提供服务,客 ...

  6. java多态的实现原理(JVM调用过程)(综合多篇文章,参考见文末)

    一个对象变量可以指示多种实际类型的现象称为多态 允许不同类的对象对同一消息做出响应.方法的重载.类的覆盖正体现了多态. 1.多态的机制 1.1 本质上多态分两种 1.编译时多态(又称静态多态) 2.运 ...

  7. 从Java future 到 Guava ListenableFuture实现异步调用

    从Java future 到 Guava ListenableFuture实现异步调用 置顶 2016年04月24日 09:11:14 皮斯特劳沃 阅读数:17570 标签: java异步调用线程非阻 ...

  8. Atitit java c# php c++ js跨语言调用matlab实现边缘检测等功能attilax总结

    Atitit java c# php c++ js跨语言调用matlab实现边缘检测等功能attilax总结 1.1. 边缘检测的基本方法Canny最常用了1 1.2. 编写matlab边缘检测代码, ...

  9. 【Java EE 学习 80 下】【调用WebService服务的四种方式】【WebService中的注解】

    不考虑第三方框架,如果只使用JDK提供的API,那么可以使用三种方式调用WebService服务:另外还可以使用Ajax调用WebService服务. 预备工作:开启WebService服务,使用jd ...

随机推荐

  1. Oracle 日期各个部分常用写法

    --1.日期的各部分的常用的的写法 --- --1) 取时间点的年份的写法: SELECT TO_CHAR(SYSDATE,'YYYY') FROM DUAL; --结果:2019 --2) 取时间点 ...

  2. mvn命令修改pom打包的版本号

    在java项目中打包经常需要修改镜像的版本号.可以使用如下命令 mvn versions: // 如果要打包使用人如下命令,打印详细信息使用 -X mvn clean deploy -e -Dskip ...

  3. python开发笔记-str转字典

    后台接收到post请求数据格式为json格式的字符串,不能直接用字典的get方法 909090909090909090909090909090909 Internal Server Error: /g ...

  4. kafka window环境下使用(内置zookeeper)

    下载 kafka 官网下载最新版本(已集成 zookeeper) 解压到 D 盘的 kafka_2.12-2.3.0 运行 zookeeper 执行 zookeeper 运行命令 D:\kafka_2 ...

  5. linux 结束某个进程,并且结束子进程

    pid=49184 childid=`ps -ef|grep $pid|grep -v grep|awk '{printf " %s",$2 }'` kill -9 $childi ...

  6. JS调用onBackPressed

    需求: 安卓页面webview加载H5页面,H5页面能能返回到安卓页面 import android.os.Bundle; import android.support.v7.app.AppCompa ...

  7. Django的分页器 paginator

    导入 from django.core.paginator import Paginator,EmptyPage,PageNotAnInteger Page对象 Paginator.page()将返回 ...

  8. Flask自动刷新前端页面(方便调试)livereload

    是不是每次调整模板文件,就要停止flask服务器,重启flask服务器,再去浏览器刷新页面? 有没有办法自动完成这3步呢? 安装livereload即可, 仅仅把app.run() 改为下面的例子就可 ...

  9. 【Maven学习】定制库到Maven本地资源库

    目标:手工操作将一个jar安装到本地仓库 第一步:首先获取到jar包,可以是第三方的 也可以是自己创建的,放到本地任意目录 比如:joda-time-2.10.3,放到C:\jar\  目录下面 第二 ...

  10. Vue父子组件相互传值及调用方法的方案

    Vue父子组件相互传值及调用方法的方案 一.调用方法: 1.父组件调用子组件方法: 2.子组件调用父组件方法: 参考:https://www.cnblogs.com/jin-zhe/p/9523782 ...