错误“解析值时遇到意外字符”

时间:2019-03-05 13:00:24

标签: c# .net-core httpclient

当我尝试通过httpClient发出http请求时,我一直收到此错误,但不知道为什么。

  

解析值时遇到意外字符:c。路径'',   第0行,位置0。“]},” title“:”一个或多个验证错误   发生。“,”状态“: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; }
}

0 个答案:

没有答案