Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
60b977c0
Commit
60b977c0
authored
Feb 27, 2023
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
导出Excel边框
parent
55d4990e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
12 deletions
+12
-12
HttpHelper.java
...src/main/java/com/yanzuoguang/util/helper/HttpHelper.java
+12
-12
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/HttpHelper.java
View file @
60b977c0
...
@@ -427,10 +427,11 @@ public class HttpHelper {
...
@@ -427,10 +427,11 @@ public class HttpHelper {
/**
/**
* post请求form-data
* post请求form-data
* @param url
*
* @param parametersBody
* @param url 请求地址
* @return
* @param parametersBody 参数值
* @throws Exception
* @return 返回值
* @throws Exception 异常
*/
*/
public
static
String
postRequest
(
String
url
,
List
<
NameValuePair
>
parametersBody
)
throws
Exception
{
public
static
String
postRequest
(
String
url
,
List
<
NameValuePair
>
parametersBody
)
throws
Exception
{
HttpEntity
entity
=
new
UrlEncodedFormEntity
(
parametersBody
,
Charsets
.
UTF_8
);
HttpEntity
entity
=
new
UrlEncodedFormEntity
(
parametersBody
,
Charsets
.
UTF_8
);
...
@@ -443,11 +444,11 @@ public class HttpHelper {
...
@@ -443,11 +444,11 @@ public class HttpHelper {
post
.
addHeader
(
"Accept"
,
"application/json"
);
post
.
addHeader
(
"Accept"
,
"application/json"
);
post
.
setEntity
(
entity
);
post
.
setEntity
(
entity
);
RequestConfig
config
=
RequestConfig
.
custom
()
RequestConfig
config
=
RequestConfig
.
custom
()
.
setConnectionRequestTimeout
(
1000
)
.
setConnectionRequestTimeout
(
HTTP_CONNECT_TIMEOUT
)
//服务端相应超时
.
setSocketTimeout
(
1000
)
//建立socket链接超时
//建立socket链接超时
.
setConnectTimeout
(
3000
)
.
setConnectTimeout
(
HTTP_CONNECT_TIMEOUT
)
//服务端相应超时
.
setSocketTimeout
(
HTTP_READ_TIMEOUT
)
.
build
();
.
build
();
post
.
setConfig
(
config
);
post
.
setConfig
(
config
);
String
var8
;
String
var8
;
...
@@ -455,12 +456,11 @@ public class HttpHelper {
...
@@ -455,12 +456,11 @@ public class HttpHelper {
HttpClient
client
=
HttpClientBuilder
.
create
().
build
();
HttpClient
client
=
HttpClientBuilder
.
create
().
build
();
HttpResponse
response
=
client
.
execute
(
post
);
HttpResponse
response
=
client
.
execute
(
post
);
int
code
=
response
.
getStatusLine
().
getStatusCode
();
int
code
=
response
.
getStatusLine
().
getStatusCode
();
String
result
=
EntityUtils
.
toString
(
response
.
getEntity
());
if
(
code
>=
400
)
{
if
(
code
>=
400
)
{
throw
new
Exception
(
EntityUtils
.
toString
(
response
.
getEntity
())
);
throw
new
HttpCodeException
(
String
.
valueOf
(
code
),
result
);
}
}
var8
=
EntityUtils
.
toString
(
response
.
getEntity
());
var8
=
result
;
}
catch
(
Exception
var11
)
{
throw
new
Exception
(
"postRequest -- Client protocol exception!"
,
var11
);
}
finally
{
}
finally
{
post
.
releaseConnection
();
post
.
releaseConnection
();
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment