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

1、服务端

参见Java调用Http接口(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接口的更多相关文章

  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. [Beta阶段]第九次Scrum Meeting

    Scrum Meeting博客目录 [Beta阶段]第九次Scrum Meeting 基本信息 名称 时间 地点 时长 第九次Scrum Meeting 19/05/15 大运村寝室6楼 40min ...

  2. 冰多多团队-第二次scrum例会

    冰多多团队-第二次Scrum会议 会议基本情况 会议时间:4月8日 19:00 - 19:30 会议地点:新主楼F座2楼沙发休息处 工作情况 团队成员 已完成任务 待完成任务 zpj Service实 ...

  3. 【Gamma阶段】第二次Scrum Meeting

    冰多多团队-Gamma阶段第二次Scrum会议 工作情况 团队成员 已完成任务 待完成任务 卓培锦 修改可移动button以及button手感反馈优化 编辑器风格切换(夜间模式) 牛雅哲 语音输入sh ...

  4. [Web] mobx 异步操作

    转载自:https://www.jianshu.com/p/66dd328726d7 异步action action只能影响正在运行的函数,而无法影响当前函数调用的异步操作 .action 包装/装饰 ...

  5. 【spring源码学习】spring事务中的嵌套事务中的保存点相关知识

    JDBC事务保存点(setSavepoint, releaseSavepoint )实例 以下是使用事务教程中描述的setSavepoint和回滚的代码示例. 此示例代码是基于前面章节中完成的环境和数 ...

  6. 【laravel5.5+Passport】laravel5的前后端分离之Passport设计

    项目中使用到了laravel5的passport组件,进行前后端分离的 api认证部分: 前后端分离的api认证,我们用的是: [密码授权令牌],需要用户登录->指定client_id/clie ...

  7. 一个按权重(weight)进行LB的算法

    package netty; import com.google.common.collect.ImmutableList; import lombok.SneakyThrows; import ja ...

  8. MySQL Unknown table engine 'FEDERATED''

    Last_SQL_Error: Error 'Unknown table engine 'FEDERATED'' on query. 错误 解决过程: 1.查看当前支持的存储引擎    show en ...

  9. url的长度问题

    url最长支持多少字符? 在http协议中,其实并没有对url长度作出限制,往往url的最大长度和用户浏览器和Web服务器有关,不一样的浏览器,能接受的最大长度往往是不一样的,当然,不一样的Web服务 ...

  10. Python 多进程爬虫实例

    Python  多进程爬虫实例 import json import re import time from multiprocessing import Pool import requests f ...