Postman 改变邮递员的反应
我使用的是开放式API 但我只使用了API提供的响应中的一小部分数据。当我使用不同参数的API进行测试时,可以看到响应 我不想每次发送请求时都看到整个API响应,我只想看到我感兴趣的数据 例如:Postman 改变邮递员的反应,postman,Postman,我使用的是开放式API 但我只使用了API提供的响应中的一小部分数据。当我使用不同参数的API进行测试时,可以看到响应 我不想每次发送请求时都看到整个API响应,我只想看到我感兴趣的数据 例如: GET : https://reqres.in/api/users?page=2 template = `<table bgcolor="#FFFFFF"> <tr> <th>Name</t
GET : https://reqres.in/api/users?page=2
template = `<table bgcolor="#FFFFFF">
<tr>
<th>Name</th>
<th>Email</th>
</tr>
{{#each response}}
<tr>
<td>{{first_name}}</td>
<td>{{email}}</td>
</tr>
{{/each}}
</table>
`;
// Set visualizer
pm.visualizer.set(template, {
// Pass the response body parsed as JSON as `data`
response: pm.response.json().data
});
template = `
<pre><code>{{response}}</code></pre>
`;
console.log( JSON.stringify(pm.response.json().data, undefined, 2))
// Set visualizer
pm.visualizer.set(template, {
// Pass the response body parsed as JSON as `data`
response: JSON.stringify(pm.response.json().data, undefined, 2)
});
响应有3个对象<代码>状态,功能
和数据
。但是我只对数据
对象感兴趣,我只想在发出请求时看到数据
对象
是否有一种方法可以使用请求的实际响应打印不同的响应
运行测试以验证数据,并使用预请求脚本在请求之前执行某些操作,但我没有发现任何更改响应形式的内容。没有修改正文的选项,但您可以使用postman中的惊人可视化工具功能: 例如:
GET : https://reqres.in/api/users?page=2
template = `<table bgcolor="#FFFFFF">
<tr>
<th>Name</th>
<th>Email</th>
</tr>
{{#each response}}
<tr>
<td>{{first_name}}</td>
<td>{{email}}</td>
</tr>
{{/each}}
</table>
`;
// Set visualizer
pm.visualizer.set(template, {
// Pass the response body parsed as JSON as `data`
response: pm.response.json().data
});
template = `
<pre><code>{{response}}</code></pre>
`;
console.log( JSON.stringify(pm.response.json().data, undefined, 2))
// Set visualizer
pm.visualizer.set(template, {
// Pass the response body parsed as JSON as `data`
response: JSON.stringify(pm.response.json().data, undefined, 2)
});
设置url和方法:
GET : https://reqres.in/api/users?page=2
template = `<table bgcolor="#FFFFFF">
<tr>
<th>Name</th>
<th>Email</th>
</tr>
{{#each response}}
<tr>
<td>{{first_name}}</td>
<td>{{email}}</td>
</tr>
{{/each}}
</table>
`;
// Set visualizer
pm.visualizer.set(template, {
// Pass the response body parsed as JSON as `data`
response: pm.response.json().data
});
template = `
<pre><code>{{response}}</code></pre>
`;
console.log( JSON.stringify(pm.response.json().data, undefined, 2))
// Set visualizer
pm.visualizer.set(template, {
// Pass the response body parsed as JSON as `data`
response: JSON.stringify(pm.response.json().data, undefined, 2)
});
在测试脚本中添加以下代码:
GET : https://reqres.in/api/users?page=2
template = `<table bgcolor="#FFFFFF">
<tr>
<th>Name</th>
<th>Email</th>
</tr>
{{#each response}}
<tr>
<td>{{first_name}}</td>
<td>{{email}}</td>
</tr>
{{/each}}
</table>
`;
// Set visualizer
pm.visualizer.set(template, {
// Pass the response body parsed as JSON as `data`
response: pm.response.json().data
});
template = `
<pre><code>{{response}}</code></pre>
`;
console.log( JSON.stringify(pm.response.json().data, undefined, 2))
// Set visualizer
pm.visualizer.set(template, {
// Pass the response body parsed as JSON as `data`
response: JSON.stringify(pm.response.json().data, undefined, 2)
});
`;
log(JSON.stringify(pm.response.JSON().data,未定义,2))
//集合可视化器
pm.visualizer.set(模板{
//将解析为JSON的响应体作为`data'传递`
响应:JSON.stringify(pm.response.JSON().data,未定义,2)
});
输出:
GET : https://reqres.in/api/users?page=2
template = `<table bgcolor="#FFFFFF">
<tr>
<th>Name</th>
<th>Email</th>
</tr>
{{#each response}}
<tr>
<td>{{first_name}}</td>
<td>{{email}}</td>
</tr>
{{/each}}
</table>
`;
// Set visualizer
pm.visualizer.set(template, {
// Pass the response body parsed as JSON as `data`
response: pm.response.json().data
});
template = `
<pre><code>{{response}}</code></pre>
`;
console.log( JSON.stringify(pm.response.json().data, undefined, 2))
// Set visualizer
pm.visualizer.set(template, {
// Pass the response body parsed as JSON as `data`
response: JSON.stringify(pm.response.json().data, undefined, 2)
});
您好,您所说的答复形式是什么意思,您能添加一个example@PDHide我编辑了这个问题,希望现在能弄清楚你所说的print console.log()或postman用户界面是什么意思。在脚本中,您可以打印任何需要的内容并在控制台中查看。但在ui的响应会话中,yiu无法在响应视图中执行此操作。因为在那里我可以关闭和搜索,而在日志中我无法查看它的格式添加了答案这实际上很好,我可以在表中看到响应,而不仅仅是原始数据。但我不认为我能让它发挥作用?我复制了一个json模板,没有日志,它仍然显示一个空文本。
response
是一个变量,还是它会自动接受它?另外,我在你的代码中没有看到let或var,我不认为JS有这些牵连吗?@AhmadSattout只需使用示例中提到的url,并按原样复制代码即可。了解它是如何工作的,然后尝试使用您的端点,并根据您的contextLet修改代码,或者在分配操作时不需要var声明。但是使用let(而不是var)是一个很好的实践谢谢,这是一个非常好的特性