httpclient 工具类

2023-11-01

1.类

package com.cainiao.manage.utils;

import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.*;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.message.BasicHeader;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 *
 * @项目名称:common
 * @类名称:ApiService
 * @类描述:负责和外部接口对接,发起http请求
 * @创建人:cainiao
 * @创建时间:2015年10月13日 下午2:55:09 
 * @version:1.0.0
 */
@Service
public class HttpService {

    @Autowired(required = false)
    private CloseableHttpClient httpClient;

    @Autowired(required = false)
    private RequestConfig requestConfig;

    /**
     *
     * @描述:发送不带参数的GET请求,返回String类型数据
     * @创建人:cainiao
     * @param url 请求地址
     * @return
     * @throws ClientProtocolException
     * @throws IOException
     */
    public String doGetToString(String url) throws IOException {
        HttpGet httpGet = new HttpGet(url);
        httpGet.setConfig(requestConfig);
        CloseableHttpResponse response = null;

        try {
            response = httpClient.execute(httpGet);
            if (response.getStatusLine().getStatusCode() == 200) {
                // 响应成功,返回数据
                return EntityUtils.toString(response.getEntity(), "UTF-8");
            }
        } finally {
            // 关闭请求,释放资源
            if (response != null) {
                response.close();
            }
        }
        return null;
    }

    /**
     *
     * @描述:带参数的GET请求,返回String类型数据
     * @创建人:cainiao
     * @param url 请求地址
     * @param param 请求参数
     * @return
     * @throws URISyntaxException
     * @throws ClientProtocolException
     * @throws IOException
     */
    public String doGetToString(String url, Map<String, Object> param)
            throws URISyntaxException,IOException {

        // 定义参数
        URIBuilder uriBuilder = new URIBuilder(url);
        for (Map.Entry<String, Object> entry : param.entrySet()) {
            uriBuilder
                    .setParameter(entry.getKey(), entry.getValue().toString());
        }
        return doGetToString(uriBuilder.build().toString());
    }

    /**
     *
     * @描述:执行DoGET请求,返回HttpResult
     * @创建人:cainiao
     * @param url 请求地址
     * @return 如果响应是200,返回具体的响应内容,其他响应返回null
     * @throws ClientProtocolException
     * @throws IOException
     */
    public HttpResult doGet(String url) throws
            IOException {
        // 创建http GET请求
        HttpGet httpGet = new HttpGet(url);
        httpGet.setConfig(this.requestConfig);
        CloseableHttpResponse response = null;
        try {
            // 执行请求
            response = httpClient.execute(httpGet);
            HttpResult result = new HttpResult();
            result.setCode(response.getStatusLine().getStatusCode());
            if (response.getEntity() != null) {
                result.setBody(EntityUtils.toString(response.getEntity(),
                        "UTF-8"));
            }
            return result;
        } finally {
            if (response != null) {
                response.close();
            }
        }
    }

    /**
     *
     * @描述:带有参数的GET请求,返回HttpResult
     * @创建人:cainiao
     * @param url 请求地址
     * @param param 请求参数
     * @return
     * @throws ClientProtocolException
     * @throws IOException
     * @throws URISyntaxException
     */
    public HttpResult doGet(String url, Map<String, Object> param)
            throws IOException, URISyntaxException {
        // 定义请求的参数
        URIBuilder uriBuilder = new URIBuilder(url);
        for (Map.Entry<String, Object> entry : param.entrySet()) {
            uriBuilder
                    .addParameter(entry.getKey(), entry.getValue().toString());
        }
        return doGet(uriBuilder.build().toString());
    }

    /**
     *
     * @描述:指定POST请求
     * @创建人:cainiao
     * @param url 请求地址
     * @param param 请求参数
     * @return 状态码和请求的body
     * @throws IOException
     */
    public HttpResult doPost(String url, Map<String, Object> param)
            throws IOException {
        // 创建http POST请求
        HttpPost httpPost = new HttpPost(url);
        httpPost.setConfig(this.requestConfig);
        if (param != null) {
            // 设置post参数
            List<NameValuePair> parameters = new ArrayList<NameValuePair>(0);
            for (Map.Entry<String, Object> entry : param.entrySet()) {
                parameters.add(new BasicNameValuePair(entry.getKey(), entry
                        .getValue() + ""));
            }
            // 构造一个form表单式的实体,并且指定参数的编码为UTF-8
            UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(
                    parameters, "UTF-8");
            // 将请求实体设置到httpPost对象中
            httpPost.setEntity(formEntity);
        }
        CloseableHttpResponse response = null;
        try {
            // 执行请求
            response = httpClient.execute(httpPost);
            if (response.getEntity() != null) {
                return new HttpResult(response.getStatusLine().getStatusCode(),
                        EntityUtils.toString(response.getEntity(), "UTF-8"));
            }
            return new HttpResult(response.getStatusLine().getStatusCode(),
                    null);
        } finally {
            if (response != null) {
                response.close();
            }
        }
    }

    /**
     *
     * @描述:指定POST请求
     * @创建人:cainiao
     * @param url 请求地址
     * @param param 请求参数
     * @return 状态码和请求的body
     * @throws IOException
     */
    public HttpResult doPostPic(String url, Map<String, Object> param)
            throws IOException {
        // 创建http POST请求
        HttpPost httpPost = new HttpPost(url);
        httpPost.setConfig(this.requestConfig);
        httpPost.addHeader("Content-Type", "multipart/form-data");
        if (param != null) {
            // 设置post参数
            List<NameValuePair> parameters = new ArrayList<NameValuePair>(0);
            for (Map.Entry<String, Object> entry : param.entrySet()) {
                parameters.add(new BasicNameValuePair(entry.getKey(), entry
                        .getValue() + ""));
            }
            // 构造一个form表单式的实体,并且指定参数的编码为UTF-8
            UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(
                    parameters, "UTF-8");
            // 将请求实体设置到httpPost对象中
            httpPost.setEntity(formEntity);
        }
        CloseableHttpResponse response = null;
        try {
            // 执行请求
            response = httpClient.execute(httpPost);
            if (response.getEntity() != null) {
                return new HttpResult(response.getStatusLine().getStatusCode(),
                        EntityUtils.toString(response.getEntity(), "UTF-8"));
            }
            return new HttpResult(response.getStatusLine().getStatusCode(),
                    null);
        } finally {
            if (response != null) {
                response.close();
            }
        }
    }

    /**
     *
     * @描述:执行PUT请求
     * @创建人:cainiao
     * @param url 请求地址
     * @param param 请求参数
     * @return 状态码和请求的body
     * @throws IOException
     */
    public HttpResult doPut(String url, Map<String, Object> param)
            throws IOException {
        // 创建http POST请求
        HttpPut httpPut = new HttpPut(url);
        httpPut.setConfig(this.requestConfig);
        if (param != null) {
            // 设置post参数
            List<NameValuePair> parameters = new ArrayList<NameValuePair>(0);
            for (Map.Entry<String, Object> entry : param.entrySet()) {
                parameters.add(new BasicNameValuePair(entry.getKey(), entry
                        .getValue().toString()));
            }
            // 构造一个form表单式的实体,并且指定参数的编码为UTF-8
            UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(
                    parameters, "UTF-8");
            // 将请求实体设置到httpPost对象中
            httpPut.setEntity(formEntity);
        }

        CloseableHttpResponse response = null;
        try {
            // 执行请求
            response = httpClient.execute(httpPut);
            if (response.getEntity() != null) {
                return new HttpResult(response.getStatusLine().getStatusCode(),
                        EntityUtils.toString(response.getEntity(), "UTF-8"));
            }
            return new HttpResult(response.getStatusLine().getStatusCode(),
                    null);
        } finally {
            if (response != null) {
                response.close();
            }
        }
    }

    /**
     *
     * @描述:指定POST请求
     * @创建人:cainiao
     * @param url 请求地址
     * @param json 请求参数
     * @return
     * @throws IOException
     */
    public HttpResult doPostJson(String url, String json) throws IOException {
        // 创建http POST请求
        HttpPost httpPost = new HttpPost(url);
        httpPost.setConfig(this.requestConfig);
        if (json != null) {
            // 构造一个字符串的实体
            StringEntity stringEntity = new StringEntity(json,
                    ContentType.APPLICATION_JSON);
            // 将请求实体设置到httpPost对象中
            httpPost.setEntity(stringEntity);
        }

        CloseableHttpResponse response = null;
        try {
            // 执行请求
            response = httpClient.execute(httpPost);
            if (response.getEntity() != null) {
                return new HttpResult(response.getStatusLine().getStatusCode(),
                        EntityUtils.toString(response.getEntity(), "UTF-8"));
            }
            return new HttpResult(response.getStatusLine().getStatusCode(),
                    null);
        } finally {
            if (response != null) {
                response.close();
            }
        }
    }

    /**
     *
     * @描述:没有参数的post请求
     * @创建人:cainiao
     * @param url 请求地址
     * @return
     * @throws IOException
     */
    public HttpResult doPost(String url) throws IOException {
        return doPost(url, null);
    }

    /**
     *
     * @描述:执行PUT请求
     * @创建人:cainiao
     * @param url 请求地址
     * @return 状态码和请求的body
     * @throws IOException
     */
    public HttpResult doPut(String url) throws IOException {
        return this.doPut(url, null);
    }

    /**
     *
     * @描述:执行DELETE请求,通过POST提交,_method指定真正的请求方法
     * @创建人:cainiao
     * @param url 请求地址
     * @param param 请求参数
     * @return 状态码和请求的body
     * @throws IOException
     */
    public HttpResult doDelete(String url, Map<String, Object> param)
            throws IOException {
        param.put("_method", "DELETE");
        return this.doPost(url, param);
    }

    /**
     *
     * @描述:执行DELETE请求(真正的DELETE请求)
     * @创建人:cainiao
     * @param url 请求地址
     * @return 状态码和请求的body
     * @throws IOException
     */
    public HttpResult doDelete(String url) throws IOException {
        // 创建http DELETE请求
        HttpDelete httpDelete = new HttpDelete(url);
        httpDelete.setConfig(this.requestConfig);
        CloseableHttpResponse response = null;
        try {
            // 执行请求
            response = httpClient.execute(httpDelete);
            if (response.getEntity() != null) {
                return new HttpResult(response.getStatusLine().getStatusCode(),
                        EntityUtils.toString(response.getEntity(), "UTF-8"));
            }
            return new HttpResult(response.getStatusLine().getStatusCode(),
                    null);
        } finally {
            if (response != null) {
                response.close();
            }
        }
    }

    /**
     *
     * @描述:httpCilent多图片上传和多个参数
     * @创建人:cainiao
     * @param url
     * @param params
     * @param files file对象必须包含图片地址
     * @return
     * @throws IOException
     */
    public HttpResult postUploadFile(String url, Map<String, Object> params,
            Map<String, File> files) throws IOException {
        HttpPost httpPost = new HttpPost(url);// 创建 HTTP POST 请求
        httpPost.setConfig(this.requestConfig);
        MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        builder.setCharset(Charset.forName("UTF-8"));// 设置请求的编码格式
        builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);// 设置浏览器兼容模式
        // 设置参数
        if (files != null) {
            // 设置图片参数
            for (Map.Entry<String, File> entry : files.entrySet()) {
                builder.addBinaryBody(entry.getKey(), entry.getValue());
            }
        }
        // 设置参数
        if (params != null) {
            // 设置post参数
            for (Map.Entry<String, Object> entry : params.entrySet()) {
                // 指定编码,防止中文乱码问题。但是某些情况下会导致上传失败
                builder.addTextBody(entry.getKey(),
                        String.valueOf(entry.getValue()),
                        ContentType.create("text/plain", "UTF-8"));
            }
        }
        // 生成 HTTP POST 实体
        HttpEntity entity = builder.build();
        /**
         * 有些网站后台使用的编码和页面源码上写的编码不一致
         * 或者页面上的编码,和后台服务的编码不一致。页面上都是gbk的,服务器端都是utf-8的,就会导致上传失败;
         * 解决办法:强制去除contentType中的编码设置
         */
        // 强制去除contentType中的编码设置,否则,在某些情况下会导致上传失败
        // boolean forceRemoveContentTypeCharset = (Boolean)
        // params.get(".rmCharset");
        // if (forceRemoveContentTypeCharset) {
        // removeContentTypeChraset("UTF-8", entity);
        // }
        // 设置请求参数
        httpPost.setEntity(entity);
        CloseableHttpResponse response = null;
        try {
            // 执行请求
            response = httpClient.execute(httpPost);
            if (response.getEntity() != null) {
                return new HttpResult(response.getStatusLine().getStatusCode(),
                        EntityUtils.toString(response.getEntity(), "UTF-8"));
            }
            return new HttpResult(response.getStatusLine().getStatusCode(),
                    null);
        } finally {
            if (response != null) {
                response.close();
            }
        }
    }

    /**
     * @param url servlet的地址 
     * @param params 要传递的参数 
     * @param files 要上传的文件 
     * @return true if upload success else false 
     * @throws ClientProtocolException
     * @throws IOException
     */
    // @SuppressWarnings("all")
    // private boolean uploadFiles(String url, Map<String, String> params,
    // ArrayList<File> files) throws ClientProtocolException, IOException {
    // HttpClient client = new DefaultHttpClient();// 开启一个客户端 HTTP 请求
    // HttpPost post = new HttpPost(url);// 创建 HTTP POST 请求
    // MultipartEntityBuilder builder = MultipartEntityBuilder.create();
    // // builder.setCharset(Charset.forName("uft-8"));//设置请求的编码格式
    // builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);// 设置浏览器兼容模式
    // int count = 0;
    // for (File file : files) {
    // // FileBody fileBody = new FileBody(file);//把文件转换成流对象FileBody
    // // builder.addPart("file"+count, fileBody);
    // builder.addBinaryBody("file" + count, file);
    // count++;
    // }
    // builder.addTextBody("method", params.get("method"));// 设置请求参数
    // builder.addTextBody("fileTypes", params.get("fileTypes"));// 设置请求参数
    // HttpEntity entity = builder.build();// 生成 HTTP POST 实体
    // post.setEntity(entity);// 设置请求参数
    // HttpResponse response = client.execute(post);// 发起请求 并返回请求的响应
    // if (response.getStatusLine().getStatusCode() == 200) {
    // return true;
    // }
    // return false;
    // }
    /**
     *
     * @描述:
     * 这里面有一个方法removeContentTypeChraset,主要是为了解决,如果调用了setCharset,
     * </br>中文文件名不会乱码,但是在ContentType文件头中会多一个charset=xxx,而导致上传失败,
     * </br>解决办法就是强制去掉这个信息。而这个HttpEntity实际对象是MultipartFormEntity对象。
     * </br>这个类未声明public,所以只能包内访问。而且该类的contentType属性是private final类型。
     * </br>就算可以通过对象拿到这个属性,也无法修改。所以我只能通过反射来修改。
     * @创建人:wyait
     * @创建时间:2017年5月3日 下午3:53:49
     * @param encoding
     * @param entity
     */
    @SuppressWarnings("unused")
    private static void removeContentTypeChraset(String encoding,
            HttpEntity entity) {
        try {
            Class<?> clazz = entity.getClass();
            Field field = clazz.getDeclaredField("contentType");
            field.setAccessible(true); // 将字段的访问权限设为true:即去除private修饰符的影响
            if (Modifier.isFinal(field.getModifiers())) {
                Field modifiersField = Field.class
                        .getDeclaredField("modifiers"); // 去除final修饰符的影响,将字段设为可修改的
                modifiersField.setAccessible(true);
                modifiersField.setInt(field, field.getModifiers()
                        & ~Modifier.FINAL);
            }
            BasicHeader o = (BasicHeader) field.get(entity);
            field.set(entity, new BasicHeader(HTTP.CONTENT_TYPE, o.getValue()
                    .replace("; charset=" + encoding, "")));
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}

2.返回实体

package com.cainiao.manage.utils;

import org.apache.commons.lang3.StringUtils;

/**
 * 
 * @项目名称:common
 * @类名称:HttpResult
 * @类描述:客户端:封装接收到的http请求返回结果
 * @创建人:cainiao 
 * @version:1.0.0
 */
public class HttpResult {

	// 响应状态码
	private Integer code;

	// 响应体
	private String body;

	public HttpResult() {

	}

	public HttpResult(Integer code, String body) {
		super();
		this.code = code;
		if (StringUtils.isNotEmpty(body)) {
			this.body = body;
		}

	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getBody() {
		return body;
	}

	public void setBody(String body) {
		this.body = body;
	}

	@Override
	public String toString() {
		return "HttpResult [code=" + code + ", body=" + body + "]";
	}

}

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

httpclient 工具类 的相关文章

  • 更改 Ubuntu Linux 中文件夹的读/写访问权限

    我想创建一个文件夹并在创建的文件夹中写入一个文件Amazon EBS来自安装在运行 Ubuntu 的 Amazon EC2 上的 Java Servlet 的卷 我已将 EBS 卷安装在 mnt my address 但是Servlet无法
  • 使用 java 从 XML 元素中删除空格

    我有一个 JSON 如下 String str Emp name JSON Emp id 1 Salary 20997 00 我想使用 java 将此 JSON 转换为 XML 我的 java 代码在这里 JSON json JSONSer
  • 为 JSP 创建注销链接?

    当用户登录我的应用程序时 他提交一个要通过 Servlet 处理的表单 servlet 为用户创建一个会话 我如何创建一个链接以便用户可以注销 我似乎无法直接链接到 Servlet 如何删除会话并链接回主页 HttpSession sess
  • 浏览时 Java Applet 不会被终止

    当用户离开加载小程序的页面时 如何停止 Java 小程序的进程 我正在使用 Chrome 现在要杀死小程序 我必须使用窗口的任务栏并杀死进程 java exe Java applet 具有生命周期方法 那些是init start stop
  • android新手需要了解“?android:attr/actionBarSize”

    我正在经历拉尔斯 沃格尔的教程 http www vogella com articles AndroidFragments article html在使用 Fragments 时 我遇到了以下代码 android layout margi
  • Android 服务 START_STICKY START_NOT_STICKY

    我需要让我的服务始终在后台运行 并使用 startService 函数启动我的服务 无论应用程序的状态如何 我都不想重新启动服务 这是我的观察 START STICKY gt 如果应用程序启动 则服务正在重新启动 当应用程序关闭时 服务也会
  • 从 Windows Batch (cmd.exe) 中的文件读取环境变量

    我正在尝试从批处理文件中读取变量 以便稍后在批处理脚本 Java 启动器 中使用 理想情况下 我希望所有平台 Unix Windows 上的设置文件都具有相同的格式 并且也是有效的 Java 属性文件 也就是说 它应该看起来像这样 sett
  • Spring MVC 和 Struts MVC 之间的区别 [关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 Spring MVC 和 Struts MVC 之间的主要区别是什么 Spring MVC 和 Struts 之间的主要区别是 Spr
  • Netbeans 雷达插件配置

    我使用的是 Netbeans 8 0 1 在提交到 SVN 之前 我需要从 IDE 运行并检查 SonarQube 分析 我已经安装了 Netbeans Radar 插件 用于启动本地分析并检查结果 这个插件有一个名为 Get Issues
  • Maven 部署:deploy-file 发布所有文件而不是一个

    我正在使用 Maven 构建我的 Java 应用程序Maven 组装插件 https maven apache org plugins maven assembly plugin 创建一个可执行的 jar 因此 目标文件夹包含多个 jar
  • Java TCP Echo 服务器 - 广播

    我有一个简单的回显服务器 我希望当连接的用户向服务器键入任何内容时 所有其他客户端和该客户端都会收到消息 MOD 它现在不会发送给所有客户端 但它应该发送 而且我只是不知道我的代码出了什么问题 所以现在它只会将消息 MOD 发送给发送消息的
  • Runtime.getRuntime().exec(cmd) 挂起

    我正在执行一个命令 该命令返回文件的修订号 文件名 但如果执行命令时出现问题 应用程序就会挂起 我可以做什么来避免这种情况 请在下面找到我的代码 String cmd cmd C si viewhistory fields revision
  • 具有多个字符串的列表视图

    我正在尝试创建一个包含多个字符串的列表视图 现在我有一个可以实现的功能 while i lt 10 GETS DATA FROM WEBPAGE ETC a DATAFROMWEBPAGE1 b DATAFROMWEBPAGE2 c DAT
  • 异步不适用于控制器的抽象超类方法

    我有一个BaseRestControllerRest 控制器扩展的类 它有一个我想异步运行的方法 public abstract class BaseRestController Async someThreadPoolTaskExecut
  • CompletableFuture SupplyAsync

    我刚刚开始探索 Java 8 的一些并发特性 让我有点困惑的一件事是这两个静态方法 CompletableFuture
  • 在Linux中执行jar文件[关闭]

    Closed 这个问题是无关 help closed questions 目前不接受答案 我创建了一个可执行的 Java jar 文件 也就是说 我将 java 程序正确打包到 jar 文件中 包括 META INF MANIFEST 文件
  • 何时对字符串文字使用 intern()

    我看到很多这样的遗留代码 class A public static final String CONSTANT value intern 我看不出使用 intern 的任何原因 因为在 Javadoc 中可以读到 所有文字字符串和字符串值
  • 谷歌的Json解析Gson库:JsonElement和JsonObject有什么区别?

    public abstract class JsonElement extends Object 表示 Json 元素的类 它可以是 JsonObject JsonArray JsonPrimitive 或 JsonNull public
  • 避免加密和编码的 URL 字符串中的换行符

    我正在尝试实现一个简单的字符串编码器来混淆 URL 字符串的某些部分 以防止它们被用户弄乱 我使用的代码几乎与示例中的相同JCA指南 http docs oracle com javase 6 docs technotes guides s
  • 请解释为什么Java和C对此代码给出不同的答案

    public class Test public static void main String args int i 10 i i System out println value of i is i 输出是 10 当我在中执行类似的代码

随机推荐

  • Redis:性能风险之CPU核和NUMA架构的影响

    文章目录 关于作者 1 主流CPU架构 2 CPU多核对Redis的性能影响 3 CPU的NUMA架构对Redis的性能影响 3 1 NUMA架构 3 2 NUMA架构对Redis的影响 3 3 绑核所带来的风险及解决办法 关于作者 关于作
  • Apache commons-dbutils工具简介说明

    转自 Apache commons dbutils工具简介说明 下文笔者讲述Apache commons dbutils工具简介说明 如下所示 commons dbutils简介 commons dbutils 是Apache提供的一个开源
  • Java 稀疏数组:利用IO流实现存盘与续上盘功能

    尚硅谷数据结构教程中 稀疏数组的课后练习 中途因为写入save data文件的数字和读取出来的数字不同 让我费劲心神 最后被一个学长一下子点出来 顿然醒悟 以下是源码 import java io FileReader import jav
  • Python3中.pyi文件介绍

    在看PyTorch代码时 在一些模块中经常会发现 pyi文件 如下图所示 是PyTorch中torch optim模块中的 pyi文件 每种实现优化算法的 py文件 都有一个对应的 pyi文件 每个 pyi文件中的内容都相似 仅有类的 in
  • 词法分析之Bi-LSTM-CRF框架

    词法分析是NLP的一项重要的基础技术 包括分词 词性标注 实体识别等 其主要算法结构为基于Bi LSTM CRF算法体系 下面对Bi LSTM CRF算法体系进行介绍 引言 首先抛开深层的技术原因 来从宏观上看一下为什么LSTM Bi LS
  • python的scrapy框架----->可以使我们更加强大,为打破写许多代码而生

    目录 scrapy框架 pipeline itrm shell scrapy模拟登录 scrapy下载图片 下载中间件 scrapy框架 含义 构图 运行流程 1 scrapy框架拿到start urls构造了一个request请求 2 r
  • linux下 tomcat 日志文件过大_Linux个性化日志文件上色 tail 颜色

    Linux个性化日志文件上色 tail 颜色 ccze是一个很好的工具 它为阅读或搜索日志文件的艰巨任务带来了真正的乐趣 它使用模块化的方法来支持流行的应用程序 如Apache Postfix Exim等的自定义颜色格式 在CentOS和F
  • 软件工程期末考试题库(超全)

    文章目录 软件工程期末考试题库 选择题 填空题 判断题 简答题 画图题 软件工程期末考试题库 选择题 具有风险分析的软件生命周期模型是 C A 瀑布模型 B 喷泉模型 C 螺旋模型 D 增量模型 软件工程的基本要素包括方法 工具和 A A
  • 解决手动跳转页面,element菜单未高亮

    主要是通过修改activeIndex来进行高亮选中
  • QML树控件TreeView的使用(上)

    在Qt5 5之前是没有树控件的 我们在使用时用的是ListView来构造出一个树 Qt5 5之后的QML开发阶段 有了树控件TreeView 本篇着重记录QML的TreeView的使用 根据MVC分解文件 类 如下 TreeControll
  • Q数的定义

    1 Q数的定义 对于16位的DSP而言 Q数定义共有16种 其简化写法分别是Q15 Q14 Q13到Q0 其数学含义可以 在其标准定义中确定 分别是Q1 15 Q2 14 Q3 13到Q16 0即标准形式为 Qn m 其数学意义是Q数的最大
  • 【抓包分析tcp协议】

    一 七层网络模型与常见协议 二 协议分析工具 1 网络监听 TcpDump WireShark 适用偏底层的协议分析 2 代理Proxy 适用偏高层的协议分析 如http 推荐工具 手工测试charles 全平台 安全测试burpsuite
  • Proxy error: Could not proxy request 解决方法

    问题本质是代理失败 常见原因 1 后端相应的被代理服务器没有开启 2 代理规则写错 前后端部署的域名应一致 3 没有把vue config js中的 before require mock mock server js 注释掉 导致走代理前
  • linux-select函数详解

    写在前面 主要是参考下边的两篇文章 对文章的内容做了一些记录 使用背景 select是实现IO多路复用的一种方式 典型场景是网络多并发服务器 服务器需要和多个客户端保持连接 相关源码可参考参考中的第二篇文章 IO多路复用概念参考第三篇文章
  • ISOWEEK的算法

    算ISOWEEK的时候 通常是以 该日的所属周数 1 该年的1 4所属周数 但也有特殊的情况 case1 可能当年的一月1号到3号是属于前年的 case2 可能前年12月29到31号是属于下一年的 SQL的算法 CREATE FUNCTIO
  • 开源自动扫描工具OpenSCAP介绍

    OpenSCAP 是一个获得 SCAP 认证的免费开源的自动化扫描 基线核查 报告和自动修复工具 目前主要由 Redhat 进行维护 OpenSCAP 由工具和基线库两个部分组成 两者没有紧密的耦合关系 比如使用 http vuls io
  • 服务器ie安全增强关闭还是显示,如何关掉ie浏览器的增强安全配置

    在 Windows Sever 2012 中打开 IE 浏览器时 IE10 会出现 已启用 Internet Explorer 增强的安全配置 的提示信息 在安全性等级中会设置以 高安全性 如果我想要关闭 Internet Explorer
  • Anaconda系统配置、换源、环境隔离、pycharm环境配置一站式教程

    Anaconda配置一站式教程 欢迎访问我的博客sakura 绘梨衣 1 安装conda 这个下载 除了安装路径 无脑确定就行了 下载网址 Free Download Anaconda 选择安装系统直接下载 最好是不要安装在C盘 反对C盘战
  • Python对excel写入数据操作实例代码(只供参考)

    coding utf8 把buffer中的信息 写入到excel中 并按照要求 构造表格样式 导入readCSV模块 用来获取buffer数据 from readCSV import readCSV from readConfig impo
  • httpclient 工具类

    1 类 package com cainiao manage utils import org apache http HttpEntity import org apache http NameValuePair import org a