Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
smf-core
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit ae7f4235
由
zshaohui
编写于
2023-08-03 16:58:08 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
http增加调用
1 个父辈
3785f772
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
48 行增加
和
0 行删除
src/main/java/com/neotel/smfcore/common/utils/HttpHelper.java
src/main/java/com/neotel/smfcore/common/utils/HttpHelper.java
查看文件 @
ae7f423
...
...
@@ -34,6 +34,7 @@ import java.io.*;
import
java.net.URI
;
import
java.net.URL
;
import
java.net.URLConnection
;
import
java.net.URLDecoder
;
import
java.security.KeyManagementException
;
import
java.security.KeyStoreException
;
import
java.security.NoSuchAlgorithmException
;
...
...
@@ -391,6 +392,53 @@ public class HttpHelper {
}
}
public
static
String
post
(
String
url
,
Map
<
String
,
Object
>
paramMap
,
Map
<
String
,
String
>
headerMap
)
throws
Exception
{
HttpPost
httpPost
=
new
HttpPost
(
url
);
if
(
headerMap
!=
null
&&
!
headerMap
.
isEmpty
())
{
for
(
Map
.
Entry
<
String
,
String
>
header
:
headerMap
.
entrySet
())
{
httpPost
.
addHeader
(
header
.
getKey
(),
header
.
getValue
());
}
}
// 设置请求参数
try
{
String
param
=
""
;
if
(
paramMap
!=
null
&&
paramMap
.
size
()
>
0
)
{
Iterator
<
String
>
ite
=
paramMap
.
keySet
().
iterator
();
while
(
ite
.
hasNext
())
{
String
key
=
ite
.
next
();
// key
Object
valueObj
=
paramMap
.
get
(
key
);
String
value
=
""
;
if
(
valueObj
!=
null
)
{
value
=
valueObj
.
toString
();
}
param
+=
key
+
"="
+
value
+
"&"
;
}
param
=
param
.
substring
(
0
,
param
.
length
()
-
1
);
}
param
=
URLDecoder
.
decode
(
param
,
"UTF-8"
);
httpPost
.
setEntity
(
new
StringEntity
(
param
,
"UTF-8"
));
RequestConfig
defaultConfig
=
RequestConfig
.
custom
().
setCookieSpec
(
CookieSpecs
.
STANDARD
).
build
();
httpPost
.
setConfig
(
defaultConfig
);
}
catch
(
Exception
e
)
{
log
.
error
(
"Request params to ["
+
url
+
"] json exception:"
+
e
.
getMessage
());
}
HttpClientBuilder
httpClientBuilder
=
HttpClientBuilder
.
create
();
try
(
CloseableHttpClient
httpClient
=
httpClientBuilder
.
setSSLSocketFactory
(
getSslConnectionSocketFactory
()).
build
())
{
CloseableHttpResponse
response
=
httpClient
.
execute
(
httpPost
);
HttpEntity
entity
=
response
.
getEntity
();
String
responseContent
=
EntityUtils
.
toString
(
entity
,
"UTF-8"
);
response
.
close
();
httpClient
.
close
();
log
.
info
(
"postJsonWithAuth url=["
+
url
+
"] return= ["
+
responseContent
+
"]"
);
return
responseContent
;
}
catch
(
Exception
e
)
{
log
.
error
(
"Request to ["
+
url
+
"] failed:"
+
e
.
getMessage
());
}
return
""
;
}
private
static
String
appendString
(
String
url
,
String
paramStr
)
{
StringBuffer
stringBuffer
=
new
StringBuffer
();
stringBuffer
.
append
(
url
);
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论