下面代码很简单 就是post 数据包登陆。。但是不知道是不是我的包有问题。还是怎么回事。总是超时public string OpenReadWithHttps(string URL, string strPostdata, string strEncoding)
   {
   try
   {
   Encoding encoding = Encoding.Default;
   HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
   request.Method = "post";
   request.Accept = "text/html, application/xhtml+xml, */*";
   request.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)";
   request.ContentType = "application/x-www-form-urlencoded";
   request.Timeout = 10000000;
   string paraUrlCoded = System.Web.HttpUtility.UrlEncode("username");
   paraUrlCoded += "=" + System.Web.HttpUtility.UrlEncode("[email protected] ");
   paraUrlCoded += "&" + System.Web.HttpUtility.UrlEncode("password");
   paraUrlCoded += "=" + System.Web.HttpUtility.UrlEncode("123456");
   paraUrlCoded += "&" + System.Web.HttpUtility.UrlEncode("list");
   paraUrlCoded += "=" + System.Web.HttpUtility.UrlEncode("1");
   paraUrlCoded += "&" + System.Web.HttpUtility.UrlEncode("submit.x");
   paraUrlCoded += "=" + System.Web.HttpUtility.UrlEncode("71");
   paraUrlCoded += "&" + System.Web.HttpUtility.UrlEncode("submit.y");
   paraUrlCoded += "=" + System.Web.HttpUtility.UrlEncode("16");   byte[] buffer;
   //将URL编码后的字符串转化为字节
   buffer = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
   //设置请求的ContentLength    //byte[] buffer = encoding.GetBytes(strPostdata);
   request.ContentLength = buffer.Length;
   request.GetRequestStream().Write(buffer, 0, buffer.Length);
   HttpWebResponse response = (HttpWebResponse)request.GetResponse();
   string strS = string.Empty;
   using (StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding(strEncoding)))
   {
   strS = reader.ReadToEnd();
   }
   Response.Write(strS);
     
  }
   catch (Exception)
   {
   //return "50";
   }
   return "";
   }///调用
   protected void Button1_Click(object sender, EventArgs e)
   {
   OpenReadWithHttps("http://new.cnzz.com/user/login.php",
   "", "gb2312");
     
  }

解决方案 »

  1.   

    使用Firefox的LiveHTTPHeaders 插件,查看提交的url和表单名称
      

  2.   


     我都看过了 
    url  ("http://new.cnzz.com/user/login.php",请求的内容 [email protected]&password=123456&list=1&submit.x=92&submit.y=19 
    我组织的包也是这样的。。
      

  3.   

    (HttpWebRequest)WebRequest.Create(URL+paraUrlCoded)
      

  4.   

     public void doPost(String url, String payload) 
        {
            WebRequest req = WebRequest.Create(url);
            req.Method = "POST";
            req.ContentType = "text/plain; charset=utf-8";        // Encode the data
            byte[] encodedBytes = Encoding.UTF8.GetBytes(payload);
            req.ContentLength = encodedBytes.Length;        // Write encoded data into request stream
            Stream requestStream = req.GetRequestStream();
            requestStream.Write(encodedBytes, 0, encodedBytes.Length);
            requestStream.Close();        WebResponse result = req.GetResponse();
            
        }
      

  5.   

    private static void CallMsgCenterToSendMsgPost(string tvurl)
            {
                try
                {
                    string formUrl = mcls._tvurl;//ConfigurationSettings.AppSettings["formUrl"].ToString().Trim();//url地址
                    string formData = "TVURL=" + tvurl;
                    CookieContainer cookieContainer = new CookieContainer();
                    // 将提交的字符串数据转换成字节数组 
                    byte[] postData = Encoding.UTF8.GetBytes(formData);                // 设置提交的相关参数 
                    HttpWebRequest request = WebRequest.Create(formUrl) as HttpWebRequest;
                    Encoding myEncoding = Encoding.GetEncoding("gb2312");
                    request.Method = "POST";
                    request.KeepAlive = false;
                    request.AllowAutoRedirect = true;
                    request.ContentType = "application/x-www-form-urlencoded";
                    request.UserAgent = "Mozi9lla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
                    request.CookieContainer = cookieContainer;
                    request.ContentLength = postData.Length;                // 提交请求数据 
                    System.IO.Stream outputStream = request.GetRequestStream();
                    outputStream.Write(postData, 0, postData.Length);
                    outputStream.Close();                HttpWebResponse response;
                    Stream responseStream;
                    StreamReader reader;
                    string srcString;
                    response = request.GetResponse() as HttpWebResponse;
                    responseStream = response.GetResponseStream();
                    reader = new System.IO.StreamReader(responseStream, Encoding.UTF8);
                    srcString = reader.ReadToEnd();
                    reader.Close();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("ERROR" + ex.Message);
                }
            }
    测试过,LZ试试行不行。
      

  6.   

    http://new.cnzz.com/user/login.php参数[email protected]&password=wangwei&list=1&submit.x=64&submit.y=19
    怎么提交呀 
      

  7.   

    这样没问题啊
    string formUrl = "http://new.cnzz.com/user/login.php";
    string formData = "username={0}&password={1}&list={2}&submit.x=92&submit.y=19";
    formData = string.Format(formData, System.Web.HttpUtility.UrlEncode("[email protected]"), 123456,1);  
    CookieContainer cookieContainer = new CookieContainer();
    // 将提交的字符串数据转换成字节数组 
    byte[] postData = Encoding.UTF8.GetBytes(formData);// 设置提交的相关参数 
    HttpWebRequest request = WebRequest.Create(formUrl) as HttpWebRequest;
    Encoding myEncoding = Encoding.GetEncoding("gb2312");
    request.Method = "POST";
    request.KeepAlive = false;
    request.AllowAutoRedirect = true;
    request.ContentType = "application/x-www-form-urlencoded";
    request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
    request.CookieContainer = cookieContainer;
    request.ContentLength = postData.Length;// 提交请求数据 
    System.IO.Stream outputStream = request.GetRequestStream();
    outputStream.Write(postData, 0, postData.Length);
    outputStream.Close();HttpWebResponse response;
    Stream responseStream;
    StreamReader reader;
    string srcString;
    response = request.GetResponse() as HttpWebResponse;
    responseStream = response.GetResponseStream();
    reader = new System.IO.StreamReader(responseStream, Encoding.GetEncoding("GB2312"));
    srcString = reader.ReadToEnd();
    reader.Close();
    this.textBox1.Text = srcString;
      

  8.   

    得到的内容
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <head>
    <title>中国站长广告联盟_免费网站流量统计_商业媒体统计_数据专家cnzz.com</title>
    <link rel="Shortcut Icon" href="favicon.ico"><link type="text/css" rel="stylesheet"
    href="../user/style/cnzz_common.css?ver=8.10" />
    <link rel="stylesheet" href="./css/thickbox.css" type="text/css"
    media="screen" />
    <!--<script src='/v1/js/prototype.js'></script>-->
    <script src='/v1/js/main.js'></script> <script type='text/javascript'>
    function data_zero(siteid){
    if(confirm('确认将所有统计数据清零?')){
    document.getElementById('webid').value = siteid;
    document.forms['form1'].action = "main.php?s=site_edit&t=clear";
    document.forms['form1'].submit();
    }
    }
    function del_check(siteid){
    if(confirm("删除站点的同时会删除站点的相关服务!确认要删除该站点吗?")){
    document.getElementById('webid').value = siteid;
    document.forms['form1'].action = "main.php?s=site_edit&t=del";
    document.forms['form1'].submit();
    }
    }
    function site_data(siteid){
    var data_arr = '';
    try{
         $.get("data/site_list_data.php?siteid="+siteid+"",null, function conv_call_back(data){
        try{
         data_arr = eval("("+data+")");
    if(data_arr && data_arr[0] && data_arr[1]){
         var html = [];
                                            html.push('<tr class="tit-1">');
                                            html.push('<td width="11%">今日</td>');
                                            html.push('<td width="32%"><b>'+ data_arr[0][0] +'</b></td>');
                                            html.push('<td width="31%"><b>'+ data_arr[0][1] +'</b></td>');
                                            html.push('<td width="26%"><b>'+ data_arr[0][2] +'</b></td>');
                                            html.push('</tr>');
                                            html.push('<tr class="tit-2">');
                                            html.push('<td width="11%">昨日</td>');
                                            html.push('<td width="32%"><b>'+ data_arr[1][0] +'</b></td>');
                                            html.push('<td width="31%"><b>'+ data_arr[1][1] +'</b></td>');
                                            html.push('<td width="26%"><b>'+ data_arr[1][2] +'</b></td>');
                                            html.push('</tr>');
         $("#"+siteid+"_ty").html(html.join(''));
    }
        }catch(e){
    var html = [];
                                            html.push('<tr class="tit-1">');
                                            html.push('<td width="11%">今日</td>');
                                            html.push('<td colspan="3" style="text-align:center; color:#666;">数据加载失败</td>');
                                            html.push('</tr>');
                                            html.push('<tr class="tit-2">');
                                            html.push('<td width="11%">昨日</td>');
                                            html.push('<td colspan="3" style="text-align:center; color:#666;">数据加载失败</td>');
                                            html.push('</tr>');
                                    $("#"+siteid+"_ty").html(html.join(''));
        }
             });
    }catch(e){}
    }
    var _username = "[email protected]";
    </script>
    <style>
    #div122{
     height:72px;
     overflow:hidden;
    }
    </style>
    </head>
    <body>
     <div class="top">
        <div style="clear:both;">
            <div class="top_log"><a href="/" target=_blank><img src="/v1/images/common/CNZZ_LOGO.gif" border=0></a></div>
            <div class="top_link">[email protected]  <a href="/user/user_edit.php" > 我的帐户</a> |
             <a href="/v1/main.php?s=site_list" > 站点列表 </a>  |  <a href="http://data.cnzz.com/" target=_blank> 数据中心 </a> | <a href="http://cnrdn.com/rd.htm?id=1008425&r=http://union.cnzz.com" target=_blank>  精准广告  </a>  | <a href="http://tool.chinaz.com/" target=_blank>  站长工具 </a>  |  <a href="http://bbs.cnzz.com/" target=_blank>  统计论坛  </a>  | <a href="/user/idea.php" target=_blank> 问题反馈 </a> |  <a href="/v1/help.html" target=_blank> 帮助 </a>  | <a href="/user/logout.php"> 登岀</a> 
            </div>  
    <div class="top_userlogin">
                <div class="top_userloginb1"></div>
                <div class="top_userloginb2">
                <div id="bgclock" class="top_userinput"></div>
                </div>
              <div class="top_userloginb3"></div>
         </div>
    </div>
      

  9.   


    <div class="main"><div style="clear: both; width: 990px;">
    <div class="sue1">
    <div class="bg1"><span style="float: left;"><strong>站内公告</strong></span>
    <span style="float: right; padding-right: 10px; color: #000000;"><a
    href="news_show.php" target="_blank">查看更多</a></span></div>
    <div class="lin2" id="div122" style="height:72px;">
    <div class="newsdiv2"><a href=news_show.php?id=36 target="_blank">CNZZ统计代码升级公告</a>&nbsp;&nbsp;2012-05-16<br />为了向广大用户提供更为优质的统计服务,近期CNZZ将对统计代码分批升级,此次升级无需您更换页面上已经放置的统计代码。升级当天的统计将重新种访客cookie,“新独立访客”“回头率”数据会受到影响,其他数据不受影响。</div><div class="newsdiv2"><a href=news_show.php?id=35 target="_blank">欢迎试用CNZZ测速工具</a>&nbsp;&nbsp;2011-11-11<br />CNZZ网站测速工具为客户提供网络服务质量监测和访问速度数据分析。该工具结合CNZZ流量统计产品,帮助企业和站长有效提升网站用户忠诚度,为网站运营提供全面的数据支持。<a href="http://tool.cnzz.com/v1/main.php?c=netprobe&a=login&czac=b3600d6ca695e5a0dbc114fe1515577e"_blank">[立即试用]</a>
    </div>
    </div>
    <script>
    var c,_=Function;
    with(o=document.getElementById("div122")){ innerHTML+=innerHTML;innerHTML+=innerHTML;innerHTML+=innerHTML; onmouseover=_("c=1"); onmouseout=_("c=0");}
    (F=_("if(#%80||!c)#++,#%=o.scrollHeight>>1;setTimeout(F,#%80?7:3000);".replace(/#/g,"o.scrollTop")))();
    </script>
    </div>
    <div class="sue2">
    <div class="bg1"><span style="float: left;"><strong>常见问题</strong></span>
    <span style="float: right; padding-right: 10px;"><a
    href="/user/idea.php" target="_blank">提交问题</a> | <a
    href="/v1/help.html" target="_blank">更多</a></span></div>
    <div class="lin1">
    <ul style="margin: 0; padding-left: 15px;">
    <li><a href="/v1/help.html#wt_7">查询密码有什么用?</a></li>
    <li><a href="/v1/help.html#wt_4">是否可以保存CNZZ统计代码在本地? </a></li>
    <li><a href="/v1/help.html#wt_15">历史数据能保存多久?</a></li>
    </ul>
    </div>
    </div>
    </div>
    <div style="width:990px; margin:auto; font-size:12px;">
        <div style="clear:both; height:10px; font-size:0px;"></div>
      <div class="list-tit">
        <div class="list-tit-c">
                <span style="float:left!important; font-size:14px; margin-left:5px; height:32px; line-height:36px;"><b>站点列表</b></span><div style="margin-left:20px; width:38px; float:left; height:32px; line-height:36px;">排序:</div><div style="width:260px; float:left; padding-top:7px;"><a href=main.php?s=site_list&sort=3&everypage=20><img title="按站点名称排序" src="images/sort_name_n.gif" border=0 align="absmiddle" /></a><a href=main.php?s=site_list&sort=1&everypage=20><img title="按开通时间排序" src="images/sort_time_d.gif" border=0 align="absmiddle" /></a></div> 
        <span style="float:right;padding-top:5px; padding-left:8px;"><a href="main.php?s=site_new"><img src="images/add_site.gif" align="absmiddle" border="0" /></a></span></div>
       </div>
          <table width="100%" border="0" cellspacing="0" cellpadding="0" style="clear:both;" class="list_box" >
    <tr class="tr-bg4">
                  <td width="10%"><div class="col-1" style="color:#fff;">站点名称</div></td>
                  <td width="22%"><div class="col-2" style="color:#fff">站点URL地址</div> </td>
                  <td width="37%"><div class="col-31">
                    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tit h28" style="margin-top:0px; border:none;">
                      <tr >
                        <td width="11%">&nbsp;</td>
                        <td width="32%" style="color:#fff;">PV</td>
                        <td width="31%" style="color:#fff;">独立访客</td>
                        <td width="26%" style="color:#fff;">IP</td>
                      </tr>
                    </table>
                  </div></td>
                  <td width="13%"><div class="col-4" style="color:#fff">查看报表</div></td>
                  <td width="18%"><div class="col-5" style="color:#fff;">站点设置</div></td>
                </tr>
                <form name="form1" id="form1" action="" method="post">
    <input type=hidden name="webid" id="webid" value="" /><input
    type=hidden name="uid" id="uid" value="" /></form>
                             <tr class="tr-bg1">
                  <td><div class="col-1">百度
    </div></td>
                  <td><div class="col-2"><a href="http://www.baidu.com" title="http://www.baidu.com" target="_blank"
    style='color: #000000'>http://www.baidu.com</a></div></td>
                                <td>
                  <div class="col-3"><table id="4462755_ty" width="100%" border="0" cellspacing="0" cellpadding="0" style="margin-top:0px; border:none;">
                      <tr class="tit-1">
                        <td width="11%">今日</td>
                        <td width="32%"><b>-</b></td>
                        <td width="31%"><b>-</b></td>
                        <td width="26%"><b>-</b></td>
                      </tr>
      <tr class="tit-2">
                        <td width="11%">昨日</td>
                        <td colspan="3" style="text-align:center; color:#666;">正在加载,请稍候…</td>
                      </tr>
                    </table>
                    <script>site_data('4462755');</script>
                  </div>
                  </td>
                  <td><div class="col-4"> 
                   <a class="blue-f12" target='_blank' href="/v1/go_site.php?siteid=4462755&s_id=418">查看报表</a>
    </div></td>
                  <td><div class="col-5" style="color:#CCCCCC"><a class="blue"
    href="main.php?s=site_set&siteid=4462755&get_code=1"
    target="_blank">获取代码</a> | <a class="blue"
    href="main.php?s=site_set&siteid=4462755">设置</a> |  <a class="blue"
    href="#" style="cursor: hand;"
    onclick="data_zero(4462755)">清零</a>
     | 
    <a class="blue"
    href="#" style="cursor: hand"
    onclick="del_check(4462755)">删除</a>
    </div></td>
                </tr>
                            <tr>
                  <td height="40" colspan="5" style="text-align:center;">如希望继续添加站点,请<a href="main.php?s=site_new">点击此处</a></td>
                </tr>
                            <tr>
                  <td colspan="5">
            <div class="ftt">
      <div class="td-b" style="height:22px;float:right;"><div style="width:120px; height:20px; margin-top:2px; display:inline; float:left;"><select name="everypage" style="width:105px;" onChange="javascript:window.location.href=(this.options[this.selectedIndex].value)"><option value="main.php?s=site_list&sort=0&everypage=10&setpage">每页显示10条</option><option selected="selected">每页显示20条</option><option value="main.php?s=site_list&sort=0&everypage=30&setpage">每页显示30条</option></select></div>首页 上一页 下一页 末页 第1/1页 20条/页  共1条记录 跳到&nbsp;<input id="page" name="page" type="text" size="3" style="height:15px;"/>&nbsp;<input type="button" value="go" style="height:20px;" onclick="pageUrl(('main.php?s=site_list&sort=0'))"/><script>function pageUrl(str){var obj = document.getElementById("page").value;location.href = str+"&page="+obj+"&everypage=20";}</script>
            </div></div>   </td>
                </tr>
              </table>
              <div class="ftt">
    <span  style="float:left!important;">声明:CNZZ保证不会向用户的统计代码里放任何广告或插件。如遇到统计服务问题,请<a class="blue" href="mailto:[email protected]">联系我们</a>。</span>
              </div>
      </div>
    </div>
    </div>
    <div class="Footer">
    <h5 style="width:100%; height:1px; margin-bottom:5px; padding:0; font-size:0; background-color:#CCCCCC;"></h5>
    <a href="http://doc.cnzz.com/index.php" class="tlink" target="_blank">公司简介</a>|
    <a class="tlink" href="http://doc.cnzz.com/a/zhanchangtongji/index.html" target="_blank">产品介绍</a>|
    <a class="tlink" href="http://doc.cnzz.com/a/meitibaodao/index.html" target="_blank">媒体报道</a>|
    <a class="tlink" href="http://doc.cnzz.com/a/gongsixinxi/zhaopinxinxi/index.html" target="_blank">人才招聘</a>|
    <a href="http://doc.cnzz.com/a/gongsixinxi/lianxiwomen/index.html" class="tlink" target="_blank">联系我们</a><br />
    <center>
    <font class=foot3D color="#808080" style="FONT-SIZE: 9px; COLOR: #808080" face="Verdana,"helvetica,arial, sans-serif>CopyRight &copy; 2002-2012 cnzz.com, Inc. All Rights Reserved </font><hr width="300" color="#edf0f1" size="0"><span style="color: #999999;">ICP备:浙B2-20080101</span>&nbsp;
    <font color="#999999"></font><script src="http://s5.cnzz.com/stat.php?id=33222&web_id=33222&show=pic" language="JavaScript"></script>
    <div style="display: none;">
    <script src='http://w.cnzz.com/c.php?id=30001831&l=888' language='JavaScript' charset='gb2312'></script>
    </div></CENTER></div> <script type="text/javascript" src="./js/thickbox.js"></script>
    <script type="text/javascript" src="./js/thick_pop.js"></script>
    <script type="text/javascript"> 
    document.write(unescape("%3Cscript src='http://www.cnzz.com/about/js/hmcnzz.js' type='text/javascript'%3E%3C/script%3E"));
    </script>
    </body>
    </html>
      

  10.   

    你要搞清楚,那些内容是js加载的,而你只是得到的页面的源代码。并没有去执行js明白吗???“
      

  11.   

    要得到js加载的内容,你需要再次去请求data/site_list_data.php?siteid=4462755
      

  12.   

    发送 Cookie就可以了,浏览器不也是每个请求都发Cookie的吗???
      

  13.   

    404 是路径错误啊。,url不正确
      

  14.   

    本帖最后由 net_lover 于 2012-08-20 13:26:44 编辑