cookie 错误中的字符无效,但在邮递员中有效
Invalid characters in cookie error but work in postman
我正在尝试使用 httpclient 将 cookie 发送到某个服务器,但出现错误:
CookieException: The 'Value'='long cookie here...' _...' part of the cookie is invalid.
我正在向邮递员发送相同的 cookie,并且有效。
这是 cookie:
string cookie = "li_sugr=78e8e2c8-51ba-4427-9d2d-31d153f08778; bcookie=\"v=2&7f13241d-b492-4ee9-855a-293dbb366f8f\"; bscookie=\"v=1&20200527045426510a9a96-dbd5-4a37-87ff-68f3d8b17391AQHQ0bUA-XY_PHgvSWw9MaxmouM9qzLw\"; lissc=1; _ga=GA1.2.910054122.1590914469; li_rm=AQHhf3VaEW1_OwAAAXJp5aokDcW0uv1SkjH-tubts8o-phQSuIr4wC15zlIZxwyk7rLoFU6TTkHYdP7WGWEJUl_rR5sSY0WqftmAhsRzqlFVztPTkI2ssjq1; liap=true; JSESSIONID=\"ajax:8711401614330939693\"; _guid=6c056244-e737-4f23-bd3e-1f0cae198554; aam_uuid=17468059359603764772746282976611888394; _gcl_au=1.1.921151728.1594296418; sl=\"v=1&xsGDj\"; UserMatchHistory=AQKL-6oza1dXqQAAAXOu3v6LRxiLW73RYPzUgKqGa9qA23bxePwvslMr8nO3EhLephJVV6DmCiy7U9dCNtp8MFI_Xs4dFc8KnGifUS4MVTdTgGqFDqd3dq2jSxt1B1Kgjo1IRFRGkQ; li_oatml=AQHLbDEDYh6sqgAAAXOu3wN397e29vMyZt2S_j8QyblJ8TZqsYbOqR2ukKhn5ei6N5U6yeaA4YAPgHqIoTY4L-8kf7UxG91j; li_at=AQEDAR6o4d8BElOkAAABcmnlsrAAAAFz0uuHR1YA0AGtl0d5HMnecKIRMQ9Q_I67J8ExmnBbSws6duI_EDUI_3Mm91ZVpoRsUKlfDwhFtxOVZ9-0cpRbMcXxvgRL0HSvT9KnI0RWBlRgQnOYjWhX1zj7; _gid=GA1.2.900822691.1596522757; AMCV_14215E3D5995C57C0A495C55%40AdobeOrg=-408604571%7CMCIDTS%7C18479%7CMCMID%7C17977207650226481502797842497975721665%7CMCAAMLH-1597127563%7C6%7CMCAAMB-1597127563%7CRKhpRz8krg2tLO6pguXWp5olkAcUniQYPHaMWWgdJ3xzPWQmdj0y%7CMCOPTOUT-1596529963s%7CNONE%7CvVersion%7C4.6.0%7CMCCIDH%7C797754258; lang=v=2&lang=en-us; spectroscopyId=53396120-a620-40f3-8c8f-2a1f79e883e3; UserMatchHistory=AQJ-nIAp1eZAzwAAAXO9Q7fdD7AY_8lu6e_xEQCvSJcXonoSlIHrgl9Nb8-z_3spJhmHnyiy-0s44TH5F7b-tSdpYe6VaQ1QeP_WBoBN1eq3JowdOA9jG20Nhl9eV5xNGrHj8cd-9VQo6N-LChnViAfW9hmXdew59It8bzwXqEUraiDGWGZRfqf-aAUIpOHm7PGm14UrOprMPa6VsXfs13EexoADF8XploW7HFH_Gr_stPF4lK5fiMCeWbrB9gLwqA5gLkiQzSKsPMNNbgX2x_jSCprnMWofZ3k; lidc=\"b=VB51:s=V:r=V:g=2814:u=586:i=1596608205:t=1596694594:v=1:sig=AQG6nZzLfJCR5lpDqxH7XZmHyZWLsuA7\"";
我收到错误:
var cookieContainer = new CookieContainer();
var cv = new Cookie("Cookie", cookie);
cookieContainer.Add(uri, cv); //<------------- exception here
我从邮递员“代码”那里获取了 cookie 字符串(我可以看到 C# 的代码片段)。
我错过了什么?
我也试过 cookie = HttpUtility.UrlEncode(cookie);
但后来我从服务器收到未经授权的响应(即错误的 cookie)
尝试拆分长饼干。
像这样:
cookieContaiter.Add(uri,new Cookie("li_sugr","...");
cookieContaiter.Add(uri,new Cookie("bcookie","...");
我正在尝试使用 httpclient 将 cookie 发送到某个服务器,但出现错误:
CookieException: The 'Value'='long cookie here...' _...' part of the cookie is invalid.
我正在向邮递员发送相同的 cookie,并且有效。
这是 cookie:
string cookie = "li_sugr=78e8e2c8-51ba-4427-9d2d-31d153f08778; bcookie=\"v=2&7f13241d-b492-4ee9-855a-293dbb366f8f\"; bscookie=\"v=1&20200527045426510a9a96-dbd5-4a37-87ff-68f3d8b17391AQHQ0bUA-XY_PHgvSWw9MaxmouM9qzLw\"; lissc=1; _ga=GA1.2.910054122.1590914469; li_rm=AQHhf3VaEW1_OwAAAXJp5aokDcW0uv1SkjH-tubts8o-phQSuIr4wC15zlIZxwyk7rLoFU6TTkHYdP7WGWEJUl_rR5sSY0WqftmAhsRzqlFVztPTkI2ssjq1; liap=true; JSESSIONID=\"ajax:8711401614330939693\"; _guid=6c056244-e737-4f23-bd3e-1f0cae198554; aam_uuid=17468059359603764772746282976611888394; _gcl_au=1.1.921151728.1594296418; sl=\"v=1&xsGDj\"; UserMatchHistory=AQKL-6oza1dXqQAAAXOu3v6LRxiLW73RYPzUgKqGa9qA23bxePwvslMr8nO3EhLephJVV6DmCiy7U9dCNtp8MFI_Xs4dFc8KnGifUS4MVTdTgGqFDqd3dq2jSxt1B1Kgjo1IRFRGkQ; li_oatml=AQHLbDEDYh6sqgAAAXOu3wN397e29vMyZt2S_j8QyblJ8TZqsYbOqR2ukKhn5ei6N5U6yeaA4YAPgHqIoTY4L-8kf7UxG91j; li_at=AQEDAR6o4d8BElOkAAABcmnlsrAAAAFz0uuHR1YA0AGtl0d5HMnecKIRMQ9Q_I67J8ExmnBbSws6duI_EDUI_3Mm91ZVpoRsUKlfDwhFtxOVZ9-0cpRbMcXxvgRL0HSvT9KnI0RWBlRgQnOYjWhX1zj7; _gid=GA1.2.900822691.1596522757; AMCV_14215E3D5995C57C0A495C55%40AdobeOrg=-408604571%7CMCIDTS%7C18479%7CMCMID%7C17977207650226481502797842497975721665%7CMCAAMLH-1597127563%7C6%7CMCAAMB-1597127563%7CRKhpRz8krg2tLO6pguXWp5olkAcUniQYPHaMWWgdJ3xzPWQmdj0y%7CMCOPTOUT-1596529963s%7CNONE%7CvVersion%7C4.6.0%7CMCCIDH%7C797754258; lang=v=2&lang=en-us; spectroscopyId=53396120-a620-40f3-8c8f-2a1f79e883e3; UserMatchHistory=AQJ-nIAp1eZAzwAAAXO9Q7fdD7AY_8lu6e_xEQCvSJcXonoSlIHrgl9Nb8-z_3spJhmHnyiy-0s44TH5F7b-tSdpYe6VaQ1QeP_WBoBN1eq3JowdOA9jG20Nhl9eV5xNGrHj8cd-9VQo6N-LChnViAfW9hmXdew59It8bzwXqEUraiDGWGZRfqf-aAUIpOHm7PGm14UrOprMPa6VsXfs13EexoADF8XploW7HFH_Gr_stPF4lK5fiMCeWbrB9gLwqA5gLkiQzSKsPMNNbgX2x_jSCprnMWofZ3k; lidc=\"b=VB51:s=V:r=V:g=2814:u=586:i=1596608205:t=1596694594:v=1:sig=AQG6nZzLfJCR5lpDqxH7XZmHyZWLsuA7\"";
我收到错误:
var cookieContainer = new CookieContainer();
var cv = new Cookie("Cookie", cookie);
cookieContainer.Add(uri, cv); //<------------- exception here
我从邮递员“代码”那里获取了 cookie 字符串(我可以看到 C# 的代码片段)。
我错过了什么?
我也试过 cookie = HttpUtility.UrlEncode(cookie);
但后来我从服务器收到未经授权的响应(即错误的 cookie)
尝试拆分长饼干。
像这样:
cookieContaiter.Add(uri,new Cookie("li_sugr","...");
cookieContaiter.Add(uri,new Cookie("bcookie","...");