【发布时间】:2017-03-03 23:32:28
【问题描述】:
我想在 Azure 的 Application Insights 可用性功能中导入“.webtest”。我没有 Visual Studio 的测试版,但this MSDN article 建议使用 Fiddler 作为创建 Web 测试的另一种选择。
我需要在 REST API 上执行 2 个请求:
- 从
connect/token端点请求一个不记名令牌。 - 在
api/resources执行 GET,并在标头中使用不记名令牌(从上述请求中检索)。
这是典型的客户端凭据 OAuth 2 流程。
我似乎无法弄清楚如何使用 Fiddler 执行此操作。基本上我需要从请求 1 的响应正文中提取一个值,并将其用作请求 2 中的标头值。
这是没有传递令牌的 web 测试的样子:
<?xml version="1.0" encoding="utf-8"?>
<TestCase Name="FiddlerGeneratedWebTest" Id="" Owner="" Description="" Priority="0" Enabled="True" CssProjectStructure="" CssIteration="" DeploymentItemsEditable="" CredentialUserName="" CredentialPassword="" PreAuthenticate="True" Proxy="" RequestCallbackClass="" TestCaseCallbackClass="">
<Items>
<Request Method="POST" Version="1.1" Url="https://example.com/connect/token" ThinkTime="8" Timeout="60" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8">
<Headers>
<Header Name="Content-Type" Value="application/x-www-form-urlencoded" />
</Headers>
<FormPostHttpBody ContentType="application/x-www-form-urlencoded">
<FormPostParameter Name="client_id" Value="myclientid" UrlEncode="True" />
<FormPostParameter Name="client_secret" Value="password123" UrlEncode="True" />
<FormPostParameter Name="grant_type" Value="client_credentials" UrlEncode="True" />
<FormPostParameter Name="scope" Value="myscopes" UrlEncode="True" />
</FormPostHttpBody>
</Request>
<Request Method="GET" Version="1.1" Url="https://example.com/api/resources" ThinkTime="0" Timeout="60" ParseDependentRequests="True" FollowRedirects="True" RecordResult="True" Cache="False" ResponseTimeGoal="0" Encoding="utf-8">
<Headers>
<Header Name="Authorization" Value="Bearer {{token}}" />
</Headers>
</Request>
</Items>
</TestCase>
【问题讨论】:
标签: visual-studio visual-studio-2015 fiddler azure-application-insights