Visual studio web test for api request failure 'Invalid HTTP header characters'

别等时光非礼了梦想. 提交于 2019-12-13 07:10:37

问题


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.

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

here is the fiddler trace of the successful oauth request

What am I missing here?


回答1:


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"



来源:https://stackoverflow.com/questions/35019470/visual-studio-web-test-for-api-request-failure-invalid-http-header-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!