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
d7ba076a
Commit
d7ba076a
authored
Jul 27, 2021
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改保存历史记录
parent
3b142e18
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
1 deletion
+31
-1
HttpCodeException.java
...ava/com/yanzuoguang/util/exception/HttpCodeException.java
+15
-0
HttpHelper.java
...src/main/java/com/yanzuoguang/util/helper/HttpHelper.java
+8
-1
HttpHelperTest.java
yzg-util-base/src/test/java/helper/HttpHelperTest.java
+8
-0
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/exception/HttpCodeException.java
View file @
d7ba076a
...
...
@@ -37,6 +37,21 @@ public class HttpCodeException extends RuntimeException {
return
target
;
}
/**
* 构造函数
* throw new CodeException("01","该订单已过期",order);
* throw new CodeException("02","该订单未到使用时间",order);
*
* @param code 错误码
* @param message 错误消息
*/
public
HttpCodeException
(
String
code
,
String
message
)
{
super
(
message
);
this
.
code
=
code
;
this
.
target
=
null
;
}
/**
* 构造函数
* throw new CodeException("01","该订单已过期",order);
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/HttpHelper.java
View file @
d7ba076a
...
...
@@ -184,7 +184,14 @@ public class HttpHelper {
// flush输出流的缓冲
out
.
flush
();
int
returnCode
=
httpConn
.
getResponseCode
();
if
(
returnCode
==
HttpURLConnection
.
HTTP_OK
)
{
in
=
readStream
(
httpConn
.
getInputStream
(),
result
,
charset
);
}
else
{
throw
new
HttpCodeException
(
StringHelper
.
toString
(
returnCode
),
httpConn
.
getResponseMessage
());
}
}
catch
(
HttpCodeException
ex
)
{
throw
ex
;
}
catch
(
Exception
ex
)
{
in
=
readStream
(
httpConn
.
getErrorStream
(),
result
,
charset
);
throw
new
HttpCodeException
(
StringHelper
.
toString
(
httpConn
.
getResponseCode
()),
ex
.
getMessage
(),
result
.
toString
(),
ex
);
...
...
yzg-util-base/src/test/java/helper/HttpHelperTest.java
View file @
d7ba076a
...
...
@@ -54,4 +54,12 @@ public class HttpHelperTest {
BaiduHelper
.
BaiduDate
result
=
BaiduHelper
.
getBaiduData
(
new
Date
());
System
.
out
.
println
(
result
.
getStatus
());
}
@Test
public
void
testRequest
()
{
String
url
=
"http://39f55e6bb381.ngrok.io/reserveInfo/addSgReserveInfo.do"
;
String
post
=
"{\"appointmentDate\":\"2021-07-27\",\"arriveAddress\":\"40288ae86ccd4bc8016ccd4c84cf0001\",\"arriveTime\":\"0\",\"cardType\":\"二代身份证\",\"openid\":\"TBD\",\"visitorCardId\":\"43052419871104817X\",\"visitorName\":\"燕子\",\"visitorPhone\":\"13800138000\"}"
;
String
result
=
HttpHelper
.
post
(
url
,
post
);
System
.
out
.
println
(
result
);
}
}
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