问题描述
现在我是想在.net下直接和某网站服务器直接交互,或者是直接操作,请问有什么思路我看了前辈的一篇文章。关于利用HttpWebRequest和HttpWebResponse自动登录一个网站代码如下:usingSystem;usingSystem.Collections;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Web;usingSystem.Web.SessionState;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.HtmlControls;usingSystem.Net;usingSystem.IO;usingSystem.Text;namespacedenglu{///<summary>///SummarydescriptionforWebForm1.///</summary>publicclassWebForm1:System.Web.UI.Page{protectedSystem.Web.UI.WebControls.LabelLabel1;protectedSystem.Web.UI.WebControls.TextBoxTextBox2;protectedSystem.Web.UI.WebControls.LabelLabel2;protectedSystem.Web.UI.WebControls.TextBoxTextBox1;privatevoidPage_Load(objectsender,System.EventArgse){getPage("http://www.163.com","username=test_denglu&passwd=zou147258369&ok=确定",TextBox1);Label1.Text=TextBox1.Text;//getPage("https://www.nsldsfap.ed.gov/secure/lnhist.asp","Action=Retrieve&SSN=177602189&FirstName=&DOB=",TextBox2);//Label2.Text=TextBox2.Text;}publicvoidgetPage(Stringurl,StringparamList,TextBoxparamTextBox){WebResponseresult=null;try{WebRequestreq=WebRequest.Create(url);req.Method="POST";req.ContentType="application/x-www-form-urlencoded";StringBuilderUrlEncoded=newStringBuilder();Char[]reserved={'?','=','&'};byte[]SomeBytes=null;if(paramList!=null){inti=0,j;while(i<paramList.Length){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;StreamnewStream=req.GetRequestStream();newStream.Write(SomeBytes,0,SomeBytes.Length);newStream.Close();}else{req.ContentLength=0;}result=req.GetResponse();StreamReceiveStream=result.GetResponseStream();Encodingencode=System.Text.Encoding.GetEncoding("utf-8");StreamReadersr=newStreamReader(ReceiveStream,encode);Char[]read=newChar[256];intcount=sr.Read(read,0,256);while(count>0){Stringstr=newString(read,0,count);paramTextBox.Text+=str;count=sr.Read(read,0,256);}}catch(Exceptione){paramTextBox.Text=e.ToString();}finally{if(result!=null){result.Close();}}}#regionWebFormDesignergeneratedcodeoverrideprotectedvoidOnInit(EventArgse){////CODEGEN:ThiscallisrequiredbytheASP.NETWebFormDesigner.//InitializeComponent();base.OnInit(e);}///<summary>///RequiredmethodforDesignersupport-donotmodify///thecontentsofthismethodwiththecodeeditor.///</summary>privatevoidInitializeComponent(){this.Load+=newSystem.EventHandler(this.Page_Load);}#endregion}}编译能够成功,但是运行之后得不出自己想要的结果有朋友能给点思路或者帮忙改改吗?谢谢了
解决方案
解决方案二:
你需要模拟登陆吗?
解决方案三:
首先是要实现模拟登陆完成这一步后是再实现模拟登陆后和网站服务器的交互,比如说我模拟登陆了GOOGLE,然后敲入关键词,可以把搜索的情况显示出来。。。这个要怎么样实现啊
解决方案四:
这个最好通过WebService的方式来实现。
解决方案五:
是啊,如果是通过webservice来实现的话是很好现在我们考虑的问题是,要在别人同意的情况下把人家的东西包装成webservice,如果我们包装不了或者是别人不让我们包装,但是我们非得用到他们的东西不可的时候,我们要做的就是这个方法了,所以向现研究下
解决方案六:
在java中解决了这个问题