Cookies to Json error

seotrabajo

Новичок
Регистрация
23.02.2019
Сообщения
3
Благодарностей
0
Баллы
1
I am working with Zennolab (so c#). I am trying to save Cookies:

Код:
    var cookie = instance.GetCookie();
var splited = cookie.Split(new []{"\r\n"}, StringSplitOptions.None)
    .Select(s => s.Split('\t')).Where(w => w.Length >= 6)
    .ToArray();
var result = new List<object>();
var locale = new System.Globalization.CultureInfo("de-DE");
var baseDt = DateTime.Now.ToString("MM/dd/yyyy");
foreach (var par in splited)
    result.Add(new {
        domain = par[0],
        expirationDate = (long)(DateTime.Parse(par[4], locale) - baseDt).TotalSeconds,
        httpOnly = par[1] == "TRUE",
        name = par[5],
        path = par[2],
        secure = par[3] == "TRUE",
        value = par[6]
    });

return Global.ZennoLab.Json.JsonConvert.SerializeObject(result);
Now whenn I run it I get this error:

Type Time Message 22:19:26 Compile code of Error in action "CS0019" "Operator '-' cannot be applied to operands of type 'System.DateTime' and 'string'". [Row: 10; Column: 33]
When I run this Save Cookie Code it is working:

Код:
var cookie = instance.GetCookie();
var splited = cookie.Split(new []{"\r\n"}, StringSplitOptions.None)
    .Select(s => s.Split('\t')).Where(w => w.Length >= 6)
    .ToArray();
var result = new List<object>();
var locale = new System.Globalization.CultureInfo("en-US");
var baseDt = new DateTime(1970, 1, 1);
foreach (var par in splited)
    result.Add(new {
        domain = par[0],
        expirationDate = (long)(DateTime.Parse(par[4], locale) - baseDt).TotalSeconds,
        httpOnly = par[1] == "TRUE",
        name = par[5],
        path = par[2],
        secure = par[3] == "TRUE",
        value = par[6]
    });

return Global.ZennoLab.Json.JsonConvert.SerializeObject(result);
BUt when when I import the Cookies it says that the Cookies cant export because of:

Error: Type error for parameter details (Error processing expirationDate: NaN and infinity are not valid) for cookies.set
What can I do?

Thanks a lot!
 

VladZen

Administrator
Команда форума
Регистрация
05.11.2014
Сообщения
22 453
Благодарностей
5 913
Баллы
113
Something wrong with date format in your cookies.
 

Kamilla

Новичок
Регистрация
30.06.2020
Сообщения
1
Благодарностей
0
Баллы
1
Как это можно исправить?
 

morpheus93

Client
Регистрация
25.01.2012
Сообщения
1 058
Благодарностей
244
Баллы
63
Maybe a solution could be to learn C# ;-)
 

Yuriy Zymlex

Moderator
Команда форума
Регистрация
24.10.2016
Сообщения
6 518
Благодарностей
3 370
Баллы
113

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)