Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Y
yep
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
郭姣
yep
Commits
8a21976f
Commit
8a21976f
authored
Jul 03, 2022
by
郭姣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
222
parent
6acdd168
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
14 deletions
+15
-14
NetworkUtils.java
src/test/java/com/oto/utils/NetworkUtils.java
+15
-14
No files found.
src/test/java/com/oto/utils/NetworkUtils.java
View file @
8a21976f
...
@@ -5,6 +5,7 @@ import static io.restassured.RestAssured.*;
...
@@ -5,6 +5,7 @@ import static io.restassured.RestAssured.*;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
io.restassured.response.Response
;
import
io.restassured.response.Response
;
import
javax.xml.ws.Response
;
import
java.io.File
;
import
java.io.File
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -19,8 +20,8 @@ public class NetworkUtils {
...
@@ -19,8 +20,8 @@ public class NetworkUtils {
public
Map
<
String
,
Object
>
fileHeaders
=
new
HashMap
<
String
,
Object
>();
public
Map
<
String
,
Object
>
fileHeaders
=
new
HashMap
<
String
,
Object
>();
// 钉钉的 headers
// 钉钉的 headers
public
Map
<
String
,
Object
>
dingTalkHeaders
=
new
HashMap
<
String
,
Object
>();
//
public Map<String, Object> dingTalkHeaders = new HashMap<String, Object>();
private
volatile
static
NetworkUtils
network
;
//
private volatile static NetworkUtils network;
// 构造函数 初始化tku、content-type
// 构造函数 初始化tku、content-type
private
NetworkUtils
(){
private
NetworkUtils
(){
...
@@ -33,7 +34,7 @@ public class NetworkUtils {
...
@@ -33,7 +34,7 @@ public class NetworkUtils {
//二进制文件的headers
//二进制文件的headers
fileHeaders
.
put
(
"Content-Type"
,
"multipart/form-data"
);
fileHeaders
.
put
(
"Content-Type"
,
"multipart/form-data"
);
//钉钉的headers
//钉钉的headers
dingTalkHeaders
.
put
(
"Content-Type"
,
"application/json;charset=utf-8"
);
//
dingTalkHeaders.put("Content-Type","application/json;charset=utf-8");
}
}
//单例模式
//单例模式
...
@@ -160,17 +161,17 @@ public class NetworkUtils {
...
@@ -160,17 +161,17 @@ public class NetworkUtils {
}
}
// post 钉钉机器人
// post 钉钉机器人
public
Response
dingTalkRobot
(
Map
<
String
,
Object
>
params
)
{
//
public Response dingTalkRobot(Map<String, Object> params) {
String
jsonStr
=
JSONObject
.
toJSONString
(
params
);
//
String jsonStr = JSONObject.toJSONString(params);
Response
response
=
given
()
//
Response response = given()
.
headers
(
dingTalkHeaders
)
//
.headers(dingTalkHeaders)
.
body
(
jsonStr
)
//
.body(jsonStr)
.
post
(
dingTalkPath
);
//
.post(dingTalkPath);
if
(!
Objects
.
equals
(
response
.
statusCode
(),
200
)){
//
if (!Objects.equals(response.statusCode(),200)){
System
.
out
.
println
(
"请求状态码错误,code=【"
+
response
.
statusCode
()+
"】"
);
//
System.out.println("请求状态码错误,code=【"+response.statusCode()+"】");
}
//
}
return
response
;
//
return response;
}
//
}
/**
/**
* 带参的接口完整信息
* 带参的接口完整信息
...
...
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