哈哈,,,刚才是说笑:
这样做,用Iframe来实现,在隐藏的iframe里面,首先自己用数据进行外部提交到通行证登录验证的程序,用脚本来定时检查目标框架的网页是否载入完毕.如果完毕,检查URL,是否正确,然后,用代码,自动转向你需要转向的通行证页面.就行了.这么点小问题.
这样做,用Iframe来实现,在隐藏的iframe里面,首先自己用数据进行外部提交到通行证登录验证的程序,用脚本来定时检查目标框架的网页是否载入完毕.如果完毕,检查URL,是否正确,然后,用代码,自动转向你需要转向的通行证页面.就行了.这么点小问题.
解决方案 »
- .net中调用COM控件的问题
- C#treeview动态添加删除节点有SQL数据库
- 向各位高手求救: 急,在sql 2005中存了各种文件的路径名,怎么查询这些文件中有没有一些词语,
- 高分求助从ASP转到ASP.net如何解决网页排版的问题?
- 帮我看看这段代码有什么问题!
- 如何向sql server insert 一个ntext
- 这里不能粘贴图片吗???
- 给出我所有的分,求助 c# 如何打印指定网页,以及调用help?????????????
- 高手请教:怎么将字符串转化为二进制的BitArray?
- C# 串口控件 Serial Port 全双工的使用问题,望请教
- FTP上传和下载是要先根据所传文件的类型来选择ascii或者binary 模式,那么请问怎样判断所传文件的类型呢?(除了根据扩展名判断以外)
- 弹出一个消息框后(MessageBox)怎么得到用户点击的是确定或取消呢?
1。 通过附加一个cookiecontainer到httprequest对象中,可以得到登录后返回的代表SESSION ID的COOKIE。 见Login方法
2。 将此COOKIE包含在一个cookiecontainer中并附加到另一个HTTPREQUEST请求中,则可以实现SESSION的还原。见getPage方法
{
// Put user code to initialize the page herestring strResult;if (HttpContext.Current.Application[cookieheader] != null)
{
cookieheader = (string)HttpContext.Current.Application[cookieheader];
}
else
{
//Login into the website and keep the cookie for the session in the application variable
string strLogin = Login(http://www.thesiteyouwanttovisit/theloginpage.asp, Action=&USERID=&Password=) ;
}
strResult = getPage(http://www.thesiteyouwanttovisit/theloginpage.asp, Action=&data=) ;
//Write the result to htm file
FileStream htmFile = new FileStream(c:\save.htm, FileMode.OpenOrCreate);
StreamWriter sw = new StreamWriter(htmFile);
sw.Write(strResult);
sw.Close();
htmFile.Close();// output the result
Response.Write(strResult);
}
public static string Login(String url, String paramList)
{
HttpWebResponse res = null;
string strResult=;try
{HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = POST;
req.ContentType = application/x-www-form-urlencoded;
req.AllowAutoRedirect = false;
CookieContainer cookieCon = new CookieContainer();
req.CookieContainer = cookieCon;StringBuilder UrlEncoded = new StringBuilder();
Char[] reserved = {'?', '=', '&'};
byte[] SomeBytes = null;if (paramList != null)
{
int i=0, j;
while(i{
j=paramList.IndexOfAny(reserved, i);
if (j==-1)
{
UrlEncoded.Append(HttpUtility.UrlEncode(paramList.Substring(i, paramList.Length-i)));
break;
}
UrlEncoded.Append(HttpUtility.UrlEncode(paramList.Substring(i, j-i)));
UrlEncoded.Append(paramList.Substring(j,1));
i = j+1;
}
SomeBytes = Encoding.UTF8.GetBytes(UrlEncoded.ToString());
req.ContentLength = SomeBytes.Length;
Stream newStream = req.GetRequestStream();
newStream.Write(SomeBytes, 0, SomeBytes.Length);
newStream.Close();
}
else
{
req.ContentLength = 0;
}
res = (HttpWebResponse)req.GetResponse();
cookieheader = req.CookieContainer.GetCookieHeader(new Uri(url));
HttpContext.Current.Application.Lock();
HttpContext.Current.Application[cookieheader] = cookieheader;
HttpContext.Current.Application.UnLock();Stream ReceiveStream = res.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding(utf-8);
StreamReader sr = new StreamReader( ReceiveStream, encode );
Char[] read = new Char[256];
int count = sr.Read( read, 0, 256 );
while (count > 0)
{
String str = new String(read, 0, count);
strResult += str;
count = sr.Read(read, 0, 256);
}
}
catch(Exception e)
{
strResult = e.ToString();
}
finally
{
if ( res != null )
{
res.Close();
}
}return strResult;
}
public static string getPage(String url, String paramList)
{
HttpWebResponse res = null;
string strResult = ;try
{HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = POST;
req.KeepAlive = true;
req.ContentType = application/x-www-form-urlencoded;
CookieContainer cookieCon = new CookieContainer();
req.CookieContainer = cookieCon;
req.CookieContainer.SetCookies(new Uri(url),cookieheader);
StringBuilder UrlEncoded = new StringBuilder();
Char[] reserved = {'?', '=', '&'};
byte[] SomeBytes = null;if (paramList != null)
{
int i=0, j;
while(i{
j=paramList.IndexOfAny(reserved, i);
if (j==-1)
{
UrlEncoded.Append(HttpUtility.UrlEncode(paramList.Substring(i, paramList.Length-i)));
break;
}
UrlEncoded.Append(HttpUtility.UrlEncode(paramList.Substring(i, j-i)));
UrlEncoded.Append(paramList.Substring(j,1));
i = j+1;
}
SomeBytes = Encoding.UTF8.GetBytes(UrlEncoded.ToString());
req.ContentLength = SomeBytes.Length;
Stream newStream = req.GetRequestStream();
newStream.Write(SomeBytes, 0, SomeBytes.Length);
newStream.Close();
}
else
{
req.ContentLength = 0;
}
res = (HttpWebResponse)req.GetResponse();
Stream ReceiveStream = res.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding(utf-8);
StreamReader sr = new StreamReader( ReceiveStream, encode );
Char[] read = new Char[256];
int count = sr.Read( read, 0, 256 );
while (count > 0)
{
String str = new String(read, 0, count);
strResult += str;
count = sr.Read(read, 0, 256);
}
}
catch(Exception e)
{
strResult = e.ToString();
}
finally
{
if ( res != null )
{
res.Close();
}
}return strResult;
}