c# - Visual Studio Web 测试 api 请求失败 'Invalid HTTP header characters'

标签 c# visual-studio azure load-testing webtest

我正在尝试从 Visual Studio Web 测试中访问 Oauth2 安全 Web API。我正在使用自定义 WebTestPlugin 和自定义 WebTestRequestPlugin。 Web 测试插件只需从 azure Active Directory 获取 token 并将其推送到请求中。这似乎工作得很好。我可以看到 token 的传出请求在 fiddler 中返回。我使用 Web 测试请求插件为 API 的传出 POST 请求生成 json 字符串。我看不到该请求被解雇。我不断收到错误:请求失败:指定的值具有无效的 HTTP header 字符。参数名称:名称

自定义请求插件代码

public override void PreRequest(object sender, PreRequestEventArgs e)
    {
        var body = new StringHttpBody
        {
            BodyString = EventBuilder.EventBuilder.BuildSingleAuditEvent(_orgId, _tenantId, _hashKey),
            ContentType = "application/json"
        };
        e.Request.Body = body;
    }

我在 Visual Studio Webtest 中使用服务请求,而 String Body 变量中没有任何内容。 enter image description here

如您所见,字符串主体的属性中没有设置任何内容。 enter image description here

这是成功的 oauth 请求的 fiddler 跟踪 enter image description here

我在这里缺少什么?

最佳答案

这是身份验证 token 格式的问题。 header 值的形式为:“Authorization:Bearer”、“TokenValue” 当它应该是“Authorization:”,“Bearer TokenValue”时

关于c# - Visual Studio Web 测试 api 请求失败 'Invalid HTTP header characters',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35019470/

相关文章:

python - 为什么 HDInsight 上的 Python 脚本会失败并显示 'No module named numpy' ?

json - 用于提供 Invoke-Restmethod 的动态 Json 变量

azure - 用于在 Azure AD Multi-Tenancy 应用程序上登录的自定义品牌

c# - 在 ThreadPool 中的线程上调用 Thread.Abort

c# - RhinoMocks - 未在 AssertWasCalled 中指定所有参数

c# - 有没有一种方法可以仅使用XAML来基于“自身文本”更改Textblock前景?

c++ - "cannot convert argument 1 from ' Node<T> ' to ' std::nullptr_t"编译器错误

c# - 接口(interface)和部分类

c# 无法反序列化当前 JSON 对象

c# - Visual Studio 调试器未附加