首页 > 解决方案 > 在 .NET Core 中获取调用 3rd 方 API 的不受支持的媒体类型

问题描述

我收到不支持的媒体类型。我想我将媒体类型指定为 JSON,但仍然得到相同的错误。

这是我的代码:

           var request = new HttpRequestMessage(HttpMethod.Post, uri);
           //custom headers
            request.Headers.Add("Custom-Signature", msg);
            request.Headers.Add("Client-Id", ClientId);

            request.Content =
                new StringContent(JsonSerializer.Serialize(pr), Encoding.UTF8, "application/json");
            using var httpResponse = await client.SendAsync(request);

当我使用 Postman 时,一切正常。

标签: .nethttpclient

解决方案


推荐阅读