Skip to content

Commit 5976920

Browse files
committed
2 parents d454fde + 661ec48 commit 5976920

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

src/main/java/com/example/Application.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ public class Application {
1010

1111
public static void main(String[] args) {
1212
SpringApplication.run(Application.class, args);
13-
int fdf=2;
13+
<<<<<<< HEAD
14+
int fcf=2;
15+
=======
16+
int faf=2;
17+
>>>>>>> branch 'master' of https://github.com/FnuJava/spring-boot.git
1418
System.out.println(1);
1519
}
1620

src/main/java/com/example/httpclient/HttpClientUtil.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.example.httpclient.common.HttpMethods;
3131
import com.example.httpclient.common.Utils;
3232
import com.example.httpclient.exception.HttpProcessException;
33+
import com.example.util.RSAUtils;
3334

3435
/**
3536
* 使用HttpClient模拟发送(http/https)请求
@@ -451,7 +452,7 @@ private static String fmt2String(HttpResponse resp, String encoding) throws Http
451452
try {
452453
if (resp.getEntity() != null) {
453454
// 按指定编码转换结果实体为String类型
454-
body = EntityUtils.toString(resp.getEntity(), encoding);
455+
body = RSAUtils.getInstance().encrypt(EntityUtils.toString(resp.getEntity(), encoding));
455456
Utils.info(body);
456457
}else{//有可能是head请求
457458
body =resp.getStatusLine().toString();

src/main/java/com/example/httpclient/test/Demo.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
public class Demo {
2727

2828
public static void main(String[] args) throws HttpProcessException, FileNotFoundException {
29-
String url = "https://github.com/Arronlong/httpclientUtil";
29+
String url = "http://localhost:8080/log/getTest";
3030

3131
//最简单的使用:
32-
String html = HttpClientUtil.get(HttpConfig.custom().url(url));
32+
/* String html = HttpClientUtil.get(HttpConfig.custom()./service/http://github.com/url(url));
3333
System.out.println(html);
34-
34+
*/
3535
//---------------------------------
3636
// 【详细说明】
3737
//--------------------------------
@@ -40,6 +40,7 @@ public static void main(String[] args) throws HttpProcessException, FileNotFound
4040
Header[] headers = HttpHeader.custom()
4141
.userAgent("javacl")
4242
.other("customer", "自定义")
43+
.contentType("application/json")
4344
.build();
4445

4546
//插件式配置生成HttpClient时所需参数(超时、连接池、ssl、重试)
@@ -54,19 +55,18 @@ public static void main(String[] args) throws HttpProcessException, FileNotFound
5455
HttpClient client = hcb.build();
5556

5657
Map<String, Object> map = new HashMap<String, Object>();
57-
map.put("key1", "value1");
58-
map.put("key2", "value2");
58+
map.put("username", "value1");
5959

6060
//插件式配置请求参数(网址、请求参数、编码、client)
6161
HttpConfig config = HttpConfig.custom()
6262
.headers(headers) //设置headers,不需要时则无需设置
6363
.url(url) //设置请求的url
64-
.map(map) //设置请求参数,没有则无需设置
64+
//.map(map) //设置请求参数,没有则无需设置
6565
.encoding("utf-8") //设置请求和返回编码,默认就是Charset.defaultCharset()
6666
.client(client) //如果只是简单使用,无需设置,会自动获取默认的一个client对象
6767
//.inenc("utf-8") //设置请求编码,如果请求返回一直,不需要再单独设置
6868
//.inenc("utf-8") //设置返回编码,如果请求返回一直,不需要再单独设置
69-
//.json("json字符串") //json方式请求的话,就不用设置map方法,当然二者可以共用。
69+
.json("RTCCNdJYI0h0R49TkRVdOx39sv6tlYXlFPKNc6VHzkc=") //json方式请求的话,就不用设置map方法,当然二者可以共用。
7070
//.context(HttpCookies.custom().getContext()) //设置cookie,用于完成携带cookie的操作
7171
//.out(new FileOutputStream("保存地址")) //下载的话,设置这个方法,否则不要设置
7272
//.files(new String[]{"d:/1.txt","d:/2.txt"}) //上传的话,传递文件路径,一般还需map配置,设置服务器保存路径
@@ -75,9 +75,9 @@ public static void main(String[] args) throws HttpProcessException, FileNotFound
7575

7676
//使用方式:
7777
String result1 = HttpClientUtil.get(config); //get请求
78-
String result2 = HttpClientUtil.post(config); //post请求
78+
//String result2 = HttpClientUtil.post(config); //post请求
7979
System.out.println(result1);
80-
System.out.println(result2);
80+
//System.out.println(result2);
8181

8282
//HttpClientUtil.down(config); //下载,需要调用config.out(fileOutputStream对象)
8383
//HttpClientUtil.upload(config); //上传,需要调用config.files(文件路径数组)

0 commit comments

Comments
 (0)