c# - 错误“解析值时遇到意外字符”
问题描述
当我尝试使用 httpClient 发出 http 请求时,我不断收到此错误,但我不知道为什么。
解析值时遇到意外字符:c。路径 '',第 0 行,位置 0。"]},"title":"出现一个或多个验证错误。","status":400,
这是我的代码,我正在使用控制台应用程序发出请求:
class Program {
static void Main (string[] args) {
Data _dt = new Data();
_dt.IP = "192.156.25";
_dt.LogText = "test from http";
_dt.LogType = 1;
_dt.StoreId = 14;
_dt.StoreName = "testino";
_dt.UserId = 2;
NewAddStoreLog(_dt);
}
static void NewAddStoreLog (Data dt) {
HttpClient http = new HttpClient ();
var content = new StringContent (dt.ToString (), Encoding.UTF8, "application/json");
var result = http.PostAsync ("http://192.168.8.180:88/Logs/RecordLogs", content).Result;
string strResult = System.Text.Encoding.UTF8.GetString (result.Content.ReadAsByteArrayAsync ().Result);
System.Console.WriteLine(strResult);
}
}
public class Data {
public int StoreId { get; set; }
public int UserId { get; set; }
public string IP { get; set; }
public int LogType { get; set; } //Enum
public string LogText { get; set; }
public string StoreName { get; set; }
}
解决方案
推荐阅读
- python-3.x - keras 中的强化学习问题不学习
- mysql - 如何在仅返回一次州和城市名称的同时返回与州和城市关联的每条记录?(MySql)
- sql - 为 OpenEdge-SQL 选择列名
- javascript - JS 中的 _forEach 实现返回未定义
- c# - 在 MacOS 上嵌入 Mono 无法打印浮点数
- sql - 使用 Dim 表在 Fact 表上创建数据仓库
- python - 属性错误:“函数”对象没有属性“randint”
- curl - cURL 中的 POST 问题。找不到 -X
- pdf - Ionic 3 在带有外部 URL 的内容视图中查看 PDF
- c++ - 更改标识符类型