Visual studio web test for api request failure 

2019-09-05 15:18发布

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

custom Request plugin code

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;
    }

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

as you can see the String Body has nothing set in its properties. enter image description here

here is the fiddler trace of the successful oauth request enter image description here

What am I missing here?

1条回答
疯言疯语
2楼-- · 2019-09-05 15:50

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"

查看更多
登录 后发表回答