PostManIndex.cshtml
6.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
<div class="layui-body layui-tab-content">
<div class="layui-tab-item layui-show">
<div class="layui-main">
<div id="LAY_preview">
<form class="layui-form" action="" lay-filter="example" onsubmit="return false;">
<div class="layui-form-item">
<label class="layui-form-label">URL<label class="lable-required">*</label></label>
<div class="layui-input-block">
<input type="text" name="URL" placeholder="请输入要请求的URL" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">请求方式</label>
<div class="layui-input-block">
<select name="Method">
<option value="post">post方式</option>
<option value="get">get方式</option>
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">ContentType)</label>
<div class="layui-input-block">
<select name="ContentType">
<option value="application/json">application/json</option>
<option value="poapplication/x-www-form-urlencodedst">application/x-www-form-urlencoded</option>
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">dataType返回格式</label>
<div class="layui-input-block">
<select name="dataType" id="dataType">
<option value="json">json</option>
<option value="text">text</option>
<option value="html">html</option>
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">POST数据</label>
<div class="layui-input-block">
<textarea placeholder="请输入数据(可选项GET时不需要写) contentType: 告诉服务器,我要发什么类型的数据 dataType:告诉服务器,我要想什么类型的数据,如果没有指定,那么会自动推断" class="layui-textarea" name="Postdata"></textarea>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">Referer</label>
<div class="layui-input-block">
<input type="text" name="Referer" placeholder="请输入Referer" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">设定Header</label>
<div class="layui-input-block">
<input type="text" name="HeaderStr" placeholder="Key:Value格式,可写多个请&$隔开不要有特殊符号" class="layui-input">
</div>
</div>
<br />
<div class="layui-form-item">
<label class="layui-form-label">返回结果</label>
<div class="layui-input-block">
<textarea class="layui-textarea" id="result" rows="8" name="result"></textarea>
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" name="fromAdd" lay-filter="fromAdd" lay-submit>模拟请求</button>
<button type="button" class="layui-btn layui-btn-normal" id="btnCopyResult">复制返回结果</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
</div>
<blockquote class="layui-elem-quote" style="margin-top: 10px;">
更多我们未能呈现的示例,还有待您在多提出Bug,去深入挖掘。
</blockquote>
</form>
</div>
</div>
</div>
</div>
@section Scripts
{
<script>
layui.config({
base: "/js/",
version: 333
}).use(['system'], function () {
var form = layui.form,
sysU = new layui.system.u(),
areaName = 'Planned',
tableName = 'Tool';
var app = {
data: {
eleSubmit: "submit(fromAdd)",
eleResult: $("#result"),
eleCopy: $("#btnCopyResult"),
dataType: $("#dataType")
},
methods: {
postMan() {
form.on(app.data.eleSubmit, function (data) {
var result = sysU.requiredExtend(data.form);
if (!result) return false;
var ajaxConfig = {
data: { httpItem: data.field },
dataType: app.data.dataType.val(),
url: `/${areaName}/${tableName}/PostMan`,
success: function (json) {
app.data.eleResult.val(JSON.stringify(json));
}
};
sysU.ajax(ajaxConfig);
return false;
});
},
copyResult() {
var result = document.getElementById("result");
if (result.value == "") return;
result.select();
document.execCommand("Copy");
layer.alert("已复制好,可贴粘。", { icon: 6, shade: 0.4, time: sysU.config.msgOpenTime });
}
},
registerEvent: function () {
app.data.eleCopy.click(function () {
app.methods.copyResult();
});
},
init: function () {
app.methods.postMan();
app.registerEvent();
}
};
app.init();
});
</script>
}