api请求失败的Visual Studio Web测试“无效的HTTP标头字符" [英] Visual studio web test for api request failure 'Invalid HTTP header characters'

查看:778
本文介绍了api请求失败的Visual Studio Web测试“无效的HTTP标头字符"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Visual Studio Web测试中获得Oauth2安全Web API.我正在使用自定义WebTestPlugin和自定义WebTestRequestPlugin. Web测试插件只是从Azure活动目录中获取令牌,然后推送到请求中.这似乎工作得很好.我可以看到提要器中对令牌的传出请求又回来了.我使用一个网络测试请求插件为API的传出POST请求生成一个json字符串.我看不到该请求被解雇.我不断收到错误消息:请求失败:指定的值包含无效的HTTP标头字符.参数名称:名称

I'm trying to hit a Oauth2 secure Web API from a visual studio web test. I'm using a custom WebTestPlugin and custom WebTestRequestPlugin. The web test plugin simply gets the token from azure active directory and shoves into the request. That seems to be working just fine. I can see the outgoing request for the token comes back in fiddler. I use a web test request plugin to generate a json string string for the outgoing POST request to the API. I can't see that request getting fired off. I keep getting the error: Request failed: Specified value has invalid HTTP Header characters. Parameter name: name

自定义请求插件代码

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变量中没有任何内容.

I'm using a service request in visual studio webtest with nothing in the String Body variable.

如您所见,字符串主体的属性中未设置任何内容.

as you can see the String Body has nothing set in its properties.

这是成功的oauth请求的提琴手跟踪

here is the fiddler trace of the successful oauth request

我在这里想念什么?

推荐答案

这是auth令牌格式的问题. 标头值为:授权:承载","TokenValue" 应该是"Authorization:","Bearer TokenValue"

this was an issue with formatting of the auth token. the header value was coming through as: "Authorization: Bearer", "TokenValue" when it should have been "Authorization:", "Bearer TokenValue"

这篇关于api请求失败的Visual Studio Web测试“无效的HTTP标头字符"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆