日期:2014-05-19  浏览次数:20430 次

请教一个跨站提交数据的函数
public   static   string   PostData(string   url,   string   indata,   CookieContainer   myCookieContainer)
        {
                string   outdata   =   " ";
                HttpWebRequest   myHttpWebRequest   =   (HttpWebRequest)WebRequest.Create(url);
                myHttpWebRequest.ContentType   =   "application/x-www-form-urlencoded ";
                myHttpWebRequest.ContentLength   =   indata.Length;
                myHttpWebRequest.Method   =   "POST ";
                myHttpWebRequest.CookieContainer   =   myCookieContainer;
                Stream   myRequestStream   =   myHttpWebRequest.GetRequestStream();
                StreamWriter   myStreamWriter   =   new   StreamWriter(myRequestStream,   Encoding.GetEncoding( "gb2312 "));
                myStreamWriter.Write(indata);
                myStreamWriter.Close();
                myRequestStream.Close();
                HttpWebResponse   myHttpWebResponse   =   (HttpWebResponse)myHttpWebRequest.GetResponse();
                myHttpWebResponse.Cookies   =   myCookieContainer.GetCookies(myHttpWebRequest.RequestUri);
                Stream   myResponseStream   =   myHttpWebResponse.GetResponseStream();
                StreamReader   myStreamReader   =   new   StreamReader(myResponseStream,   Encoding.GetEncoding( "gb2312 "));
                outdata   =   myStreamReader.ReadToEnd();
                myStreamReader.Close();
                myResponseStream.Close();
                return   outdata;
        }
我要向http://mail.163.com/请求数据进行身份验证参数应该怎么写?
PostData(“http://mail.163.com/”,   string   indata,   CookieContainer   myCookieContainer)

------解决方案--------------------
需要验证码的,很难搞,不用验证码就直接POST用户名密码就可以了
------解决方案--------------------
那你首先要知道对方传递用户名密码的名字是什么比如username pwd 什么的,然后用GET
myHttpWebRequest.Method = "POST ";
传入的indata 要这样写 login.aspx?username=XXX&pwd=***

------解决方案--------------------
myHttpWebRequest.Method = "GET ";
------解决方案--------------------
public static string PostData(string url, string indata, CookieContainer myCookieContainer)
{
string outdata = " ";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] myData = encoding.GetBytes(indata);

HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);