asp.net-web-api - 标头缓存控制:无缓存
问题描述
我正在向 api 发送请求!
string url = "http://xxx.xxx.xx.xx/api/QMn/Create";
var client = new HttpClient();
client.BaseAddress = new Uri(url);
// client.Headers.ContentType = new MediaTypeHeaderValue("application/json");
StringContent content = new StringContent(JsonConvert.SerializeObject(DataToSave), Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync(url, content);
var result = await response.Content.ReadAsStringAsync();
Api 接收请求是这样的:
public void Create([FromBody] IEnumerable<QMSRejection> DataToSave)
{
try
{
_QMSRejection.Create(DataToSave);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
我收到此错误我无法理解为什么?
{StatusCode: 204, ReasonPhrase: 'No Content',
Version: 1.1, Content: System.Net.Http.StreamContent,
Headers: { Cache-Control: no-cache
Date: Fri, 28 Aug 2020 06:18:43 GMT Pragma: no-cache
Server: Microsoft-IIS/10.0 X-Android-Received-Millis: 1598595526870
X-Android-Response-Source: NETWORK 204 X-Android-Selected-Protocol: http/1.1
X-Android-Sent-Millis: 1598595526011
X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Expires: -1 }}
我是否必须传递标题,但我只需要传递正文!
解决方案
我解决了错误来自 API 端而不是客户端的问题!API中有验证导致它给出这样的错误!
推荐阅读
- flask - Flask SocketIO:WebSocket 握手期间出错
- unix - 为什么我的文本文件在 WSL Vim 上打开后在 macOS 上变得不可读?
- bash - 用 bash 计算表达式
- xamarin.forms - AzureKeyVault 集成 AzureFunction 和 xamarin 表单
- clojure - 通过键值交换地图查找中的嵌套特定项目,地图中的位置
- javascript - 没有未使用的变量
- java - 将 csv 数据加载到 Elasticsearch 失败,翻译问题
- python - 如何在python中修复“未定义序列”
- mysql - 通过 or 连接两个表
- android - 如何使用饼图可视化 Firebase 数据?