1
尝试获取Rest请求。我能够从推荐的方法获取Cookie,但无法处理以下请求。标题中列出的回复将在以下条件下返回:返回值未找到或“指定的值具有无效的HTTP标头字符。参数名称:名称”
foreach(RestResponseCookie a in response.Cookies){
if(a.Name == "JSESSIONID")
{
request.AddHeader("cookie:" + a.Name, a.Value);
}
}
response = client.Execute(request);
这将返回“指定的值具有无效的HTTP标头字符。参数名称:名称”
当试图通过
request.AddCookie(a.Name, a.Value);
的回报,而不是将这种‘未找到’,但我可以请求手动去到现场的时候。
Edit1。
通过处理所有的Cookie,而不是文档中明确声明的那个,可以解决问题。
client.CookieContainer = new CookieContainer();
foreach(RestResponseCookie a in response.Cookies){
if(a.Expires == new DateTime(0))//remove expiring cookie as stated in dat3450's answer
client.CookieContainer.Add(newCookie() {Name = a.Name, Value = a.Value, Path = a.Path, Domain = a.Domain});
}