首页 > 解决方案 > 错误“解析值时遇到意外字符”

问题描述

当我尝试使用 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; }
}

标签: c#.net-corehttpclient

解决方案


推荐阅读