问题描述
要求:先有两套系统,系统A为外网系统,系统B为自己开发系统,要求在系统B里模拟登录系统A的同时,保存登录状态,继续模拟查询,插入修改能工作~POSTDATA标签如下:parameterValsize__EVENTVALIDATION/wEWBAKs1+r2CQLs0bLrBgLs0fbZDAKM54rGBqc/HlccvtrW08kNqxhBoSJUnBKw88__VIEWSTATE/wEPDwULLTExNTc2NTI3OTlkZHbOdWF4uA82vzs960/N2fQQfeZD68Button1Button14TextBox1zyg12TextBox212312主要代码:C#codeprotectedvoidButton1_Click(objectsender,EventArgse){CookieContainercc=newCookieContainer();//thisisforkeeptheSessionandCookieHashtableparam=newHashtable();//thisisforkeeppostdata.stringurlLogin="http://localhost:2723/Calendar/WebCollection/FountainPage.aspx";//dofindtheelementIdthatneeded.checkthesourceofloginpagecangetthisinformationparam.Add("TextBox1","zyg");param.Add("TextBox2","123");param.Add("Button1","Button");param.Add("__VIEWSTATE","/wEPDwULLTExNTc2NTI3OTlkZHbOdWF4uA82vzs960/N2fQQfeZD");param.Add("__EVENTVALIDATION","/wEWBAKs1+r2CQLs0bLrBgLs0fbZDAKM54rGBqc/HlccvtrW08kNqxhBoSJUnBKw");stringresult=PostAndGetHTML(urlLogin,cc,param);Response.Write(result);}
publicstaticstringPostAndGetHTML(stringtargetURL,CookieContainercc,Hashtableparam){//preparethesubmitdatastringformData="";foreach(DictionaryEntrydeinparam){formData+=de.Key.ToString()+"="+de.Value.ToString()+"&";}if(formData.Length>0)formData=formData.Substring(0,formData.Length-1);//removelast'&'ASCIIEncodingencoding=newASCIIEncoding();byte[]data=encoding.GetBytes(formData);HttpWebRequestrequest=(HttpWebRequest)WebRequest.Create(targetURL);request.Method="POST";//postrequest.ContentType="application/x-www-form-urlencoded";request.ContentLength=data.Length;request.UserAgent="Mozilla/4.0(compatible;MSIE7.0;WindowsNT5.1;SV1;.NETCLR2.0.1124)";StreamnewStream=request.GetRequestStream();newStream.Write(data,0,data.Length);newStream.Close();request.CookieContainer=cc;HttpWebResponseresponse=(HttpWebResponse)request.GetResponse();cc.Add(response.Cookies);Streamstream=response.GetResponseStream();stringresult=newStreamReader(stream,System.Text.Encoding.Default).ReadToEnd();returnresult;}
参数我是严格按照PostData的参数形式传递的,可还是报500错误,很费解,应该不是我参数传递的问题吧。完全参照这位兄弟的操作方式~我还是失败了~哪个楼主也不见了~~哎~~http://topic.csdn.net/u/20090929/15/7dd2936e-273f-4b8a-b578-2fd09e2bc191.html
解决方案
解决方案二:
中国技术用户组合作机构