.net - 在 .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 时,一切正常。
- 我需要将 json 作为
Content-Type
. - 我还需要添加内容长度。
- Content-Type 和 Content-Length 是必填字段。
解决方案
推荐阅读
- lda - Mallet for LDA 中使用了哪种超参数优化技术?
- google-apps-script - 如何从 SpreadsheetApp 中的单元格文本值获取每个单词的属性(粗体、斜体等)
- python - 如果 a 列中的值大于 1,则在 b 列中打印单词
- r - 根据R中的其他列值删除多行
- go - 通过始终保持相同的顺序将 Map 编入 BSON
- java - 由于我没有 Gradle 版本和 Source 8,Gradle 构建失败
- web-scraping - 网络从 ebay 抓取智能手表列表
- sql - 从预定义查询列表中查找哪些 SQL 查询受 INSERT、UPDATE 或 DELETE 影响
- c# - EF Core 不会在 SaveChanges()/SaveChangesAsync() 上引发异常
- c++ - 将分配的内存写入磁盘