Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
scrm
/
rpc-scrm-entmicro
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
1
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 37a58d6c
authored
Mar 31, 2026
by
zhouhaibao
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]企微群联系我管理
1 parent
aec77127
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
0 deletions
rpc-scrm-entmicro-container/src/main/java/cn/com/glsx/entmicro/util/HttpUtils.java
rpc-scrm-entmicro-container/src/main/java/cn/com/glsx/entmicro/util/HttpUtils.java
0 → 100644
View file @
37a58d6
package
cn
.
com
.
glsx
.
entmicro
.
util
;
import
com.alibaba.fastjson.JSONObject
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.client.HttpClient
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.impl.client.HttpClientBuilder
;
import
org.apache.http.protocol.HTTP
;
import
org.apache.http.ssl.SSLContexts
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.net.URI
;
/**
* HTTP工具类
* 用于发送HTTP请求
*
* @author system
* @date 2026-03-31
*/
@Slf4j
public
class
HttpUtils
{
/**
* 发送POST请求
* @param url 请求地址
* @param params 请求参数
* @return 响应结果
*/
public
static
String
post
(
String
url
,
String
params
)
{
try
{
javax
.
net
.
ssl
.
SSLContext
ctx
=
SSLContexts
.
custom
()
.
useProtocol
(
"TLSv1.2"
).
build
();
// 定义HttpClient
HttpClient
client
=
HttpClientBuilder
.
create
().
setSslcontext
(
ctx
)
.
build
();
BufferedReader
in
=
null
;
// 实例化HTTP方法
HttpPost
request
=
new
HttpPost
();
request
.
setURI
(
new
URI
(
url
));
// 设置参数
request
.
setEntity
(
new
StringEntity
(
params
,
HTTP
.
UTF_8
));
request
.
addHeader
(
"Content-Type"
,
"application/json;charset=utf-8"
);
HttpResponse
response
=
client
.
execute
(
request
);
int
code
=
response
.
getStatusLine
().
getStatusCode
();
if
(
code
==
200
)
{
// 请求成功
in
=
new
BufferedReader
(
new
InputStreamReader
(
response
.
getEntity
().
getContent
(),
"utf-8"
));
StringBuffer
sb
=
new
StringBuffer
(
""
);
String
line
=
""
;
String
NL
=
System
.
getProperty
(
"line.separator"
);
while
((
line
=
in
.
readLine
())
!=
null
)
{
sb
.
append
(
line
+
NL
);
}
in
.
close
();
return
sb
.
toString
();
}
else
{
//
log
.
warn
(
"HTTP请求失败,状态码:{}"
,
code
);
return
null
;
}
}
catch
(
Exception
e
)
{
log
.
error
(
"HTTP请求异常"
,
e
);
return
null
;
}
}
/**
* 发送POST请求(JSON格式)
* @param url 请求地址
* @param jsonObject JSON对象
* @return 响应结果
*/
public
static
String
postJson
(
String
url
,
JSONObject
jsonObject
)
{
return
post
(
url
,
jsonObject
.
toJSONString
());
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment