公司里的服务器每次需要访问外网,都要远程上去,用浏览器填写登陆 用户名和密码,才能访问外网。
有没可能使用C#写一个服务,定时自动访问登陆网站,自动提交用户名和密码,连接外网?
听起来不难啊,可以在写个winform程序,里面定时调用访问网站的方法
public static string HttpGet(string Url, string postDataStr)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url + (postDataStr == "" ? "" : "?") + postDataStr);
request.Method = "GET";
request.ContentType = "text/html;charset=UTF-8";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
string retString = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();
return retString;
}