在dotnet核心中调试HTTP发布

时间:2020-03-11 22:31:50

标签: c# asp.net-core-2.0 dotnet-httpclient

我使用dotnet核心API从另一个API请求数据,对其进行处理并将其发送回去。到目前为止,到目前为止,我仍然遇到错误,想问一下如何调试此代码,尤其是如何获取准确的请求

这是我的代码(出于任何原因,我需要发送application / x-www-form-urlencoded以及一个名为XML = content的参数,该参数在例如邮递员中工作)

public async Task<IActionResult> blub()
{
    try
    {
        string url = @"https://url";

        var content = new List<KeyValuePair<string, string>>();
        content.Add(new KeyValuePair<string, string>("xml", "content"));
        using (var httpClient = new HttpClient())
        {
            httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/x-www-form-urlencoded");
            HttpResponseMessage httpResponse = httpClient.PostAsync(
                new Uri(url), new FormUrlEncodedContent(content)).Result;

            httpResponse.EnsureSuccessStatusCode();
            return Ok(httpResponse);
        }
    }
    catch (Exception e)
    {
        return Ok(e);
    }
}

问题是,在邮递员中,我得到200,在这里是500,我不知道如何调试它。如果我阅读httpResponse,则找不到正文,例如内容。也许这就是500的原因。 特别是,我需要看到这样的请求:

POST /xmlservice.asmx/api HTTP / 1.1主机: xml.host.com内容类型:application / x-www-form-urlencoded 内容长度:1159

xml = content

0 个答案:

没有答案