Java模拟Http请求
使用的是org.apache.httpcomponents中的httpclient,因为post请求涉及到传输文件,所以需要使用httpmime这个包
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.6</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.1</version>
</dependency>
直接上代码:
package com.yappam.gmcms.utils.web.tools;
import com.google.common.collect.Maps;
import com.yappam.gmcms.utils.encrypt.HmacUtil;
import com.yappam.gmcms.utils.string.StringUtil;
import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException