【发布时间】:2011-06-08 15:49:54
【问题描述】:
在我的项目中,我使用 C# 应用程序客户端和 tomcat6 Web 应用程序服务器。 我在 C# 客户端写了这个 sn-p:
public bool isServerOnline()
{
Boolean ret = false;
try
{
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(VPMacro.MacroUploader.SERVER_URL);
req.Method = "HEAD";
req.KeepAlive = false;
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
if (resp.StatusCode == HttpStatusCode.OK)
{
// HTTP = 200 - Internet connection available, server online
ret = true;
}
resp.Close();
return ret;
}
catch (WebException we)
{
// Exception - connection not available
Log.e("InternetUtils - isServerOnline - " + we.Status);
return false;
}
}
每次调用此方法时,我都会在服务器端获得一个新会话。 我想这是因为我应该在我的客户端中使用 HTTP cookie。但我不知道该怎么做,你能帮帮我吗?
【问题讨论】:
-
好问题!过去的转移会议让我保持清醒
-
你解决了这个问题吗?
-
我当时使用了纪尧姆的建议
-
好的,但是如何管理过期的 cookie?是用 CookieContainer 自动实现的吗?
标签: c# httpwebrequest session-cookies