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
0abb62e8
Commit
0abb62e8
authored
Oct 13, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改MQ请求尸体,防止出错
parent
589646f2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
12 deletions
+26
-12
HttpHelper.java
...src/main/java/com/yanzuoguang/util/helper/HttpHelper.java
+26
-12
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/HttpHelper.java
View file @
0abb62e8
...
...
@@ -11,6 +11,7 @@ import java.net.URLConnection;
/**
* HTTP请求工具类
*
* @author 颜佐光
*/
public
class
HttpHelper
{
...
...
@@ -65,8 +66,7 @@ public class HttpHelper {
// 设置通用属性
httpConn
.
setRequestProperty
(
"Accept"
,
"*/*"
);
httpConn
.
setRequestProperty
(
"Connection"
,
"Keep-Alive"
);
httpConn
.
setRequestProperty
(
"User-Agent"
,
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)"
);
httpConn
.
setRequestProperty
(
"User-Agent"
,
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)"
);
// 设置POST方式
httpConn
.
setDoInput
(
true
);
httpConn
.
setDoOutput
(
true
);
...
...
@@ -88,7 +88,6 @@ public class HttpHelper {
BufferedReader
in
=
null
;
PrintWriter
out
=
null
;
// 处理请求参数
// StringBuffer sb = new StringBuffer();
String
params
=
""
;
try
{
params
=
jsonString
;
...
...
@@ -98,14 +97,10 @@ public class HttpHelper {
out
.
write
(
params
);
// flush输出流的缓冲
out
.
flush
();
// 定义BufferedReader输入流来读取URL的响应,设置编码方式
in
=
new
BufferedReader
(
new
InputStreamReader
(
httpConn
.
getInputStream
(),
"UTF-8"
));
String
line
;
// 读取返回的内容
while
((
line
=
in
.
readLine
())
!=
null
)
{
result
.
append
(
line
);
}
in
=
readStream
(
httpConn
.
getInputStream
(),
result
);
}
catch
(
Exception
ex
)
{
in
=
readStream
(
httpConn
.
getErrorStream
(),
result
);
throw
new
RuntimeException
(
ex
.
getMessage
()
+
" 结果:"
+
result
.
toString
(),
ex
);
}
finally
{
if
(
out
!=
null
)
{
out
.
close
();
...
...
@@ -117,6 +112,25 @@ public class HttpHelper {
return
result
.
toString
();
}
/**
* 读取数据流
*
* @param stream
* @param result
* @return
* @throws IOException
*/
private
static
BufferedReader
readStream
(
InputStream
stream
,
StringBuilder
result
)
throws
IOException
{
// 定义BufferedReader输入流来读取URL的响应,设置编码方式
BufferedReader
in
=
new
BufferedReader
(
new
InputStreamReader
(
stream
,
"UTF-8"
));
String
line
;
// 读取返回的内容
while
((
line
=
in
.
readLine
())
!=
null
)
{
result
.
append
(
line
);
}
return
in
;
}
/**
* 下载文件
*
...
...
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