如何获取HttpRequestMessage的xml正文?

时间:2018-11-29 09:34:40

标签: httpresponse dotnet-httpclient

我有以下代码可以调用API。如何获取xml格式的响应?

        public static void MakeCall()
    {
        var client = new HttpClient();
        client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "text/xml");
        var httpRequestMessage = new HttpRequestMessage
        {
            Method = HttpMethod.Post,
            RequestUri = new Uri("http://example.com"),
            Headers = {
                { "book", "shinning" },
                { "user", "user@api.com" },
                { "pass", "secret" }
            },
    };

        var response = client.SendAsync(httpRequestMessage).Result;
        var msg = response.Content;
    }

0 个答案:

没有答案