来源页面:http://www.jpslw.com/b2cbody/FlightTicket/waiting.aspx?WebFrom=cszx0094&TripType=1&StartCity=SHE&ArrivalCity=PEK&FlyDate=2009-04-16&BackFlyDate=2009-04-16&AirCompany=&FlyTime=00:00&OrderBy=35796&Desc=&LowestPrice=&id=&CompanyNO=&WebNO=&BackFlyTime=00:00&I1.x=37&I1.y=12
在ie里输入该页面,该页面会自动提交到http://www.jpslw.com/b2cbody/FlightTicket/Query.aspx
请问如何取得http://www.jpslw.com/b2cbody/FlightTicket/Query.aspx的网页内容?
请各位大侠帮忙,100分谢谢。
我用以下代码,无法访问,提示非法参数。
        string param = "WebFrom=cszx0094&TripType=1&StartCity=SHE&ArrivalCity=PEK&FlyDate=2009-04-06&BackFlyDate=2009-04-06&AirCompany=&FlyTime=00:00&OrderBy=35796&Desc=&LowestPrice=&id=&CompanyNO=&WebNO=&BackFlyTime=00:00";
        byte[] bs = Encoding.ASCII.GetBytes(param);
     
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.jpslw.com/b2cbody/FlightTicket/query.aspx?WebFrom=cszx0094&TripType=1&StartCity=SHE&ArrivalCity=PEK&FlyDate=2009-04-16&BackFlyDate=2009-04-16&AirCompany=&FlyTime=00:00&OrderBy=35796&Desc=&LowestPrice=&id=&CompanyNO=&WebNO=&BackFlyTime=00:00&I1.x=37&I1.y=12");
        request.Method = "POST";
        request.Referer = "http://www.jpslw.com/b2cbody/FlightTicket/waiting.aspx?WebFrom=cszx0094&TripType=1&StartCity=SHE&ArrivalCity=PEK&FlyDate=2009-04-16&BackFlyDate=2009-04-16&AirCompany=&FlyTime=00:00&OrderBy=35796&Desc=&LowestPrice=&id=&CompanyNO=&WebNO=&BackFlyTime=00:00&I1.x=37&I1.y=12";
        request.AllowAutoRedirect = true;
        request.Timeout = 9999999;        request.ContentType = "application/x-www-form-urlencoded";
        request.ContentLength = bs.Length;
        using (Stream reqStream = request.GetRequestStream())
        {
            reqStream.Write(bs, 0, bs.Length);
        }
        using (WebResponse wr = request.GetResponse())
        {
            StreamReader reader = new StreamReader(wr.GetResponseStream(), System.Text.Encoding.GetEncoding("gb2312"));
            Response.Write(reader.ReadToEnd());
        } 

解决方案 »

  1.   

    答:使用javascript获取网页内容http://blog.csdn.net/hertcloud/archive/2007/03/26/1541532.aspxse 
      

  2.   

    <script   language="vbscript">   
      Function   bytes2BSTR(vIn)   
        
      Dim   strReturn,i,ThisCharCode,innerCode,Hight8,Low8,NextCharCode   
      strReturn   =   ""   
        
      For   i   =   1   To   LenB(vIn)   
      ThisCharCode   =   AscB(MidB(vIn,i,1))   
      If   ThisCharCode   <   &H80   Then   
      strReturn   =   strReturn   &   Chr(ThisCharCode)   
      Else   
      NextCharCode   =   AscB(MidB(vIn,i+1,1))   
      strReturn   =   strReturn   &   Chr(CLng(ThisCharCode)   *   &H100   +   CInt(NextCharCode))   
      i   =   i   +   1   
      End   If   
      Next   
        
      bytes2BSTR   =   strReturn   
        
      End   Function   
      </script>   
      <script   language="javascript">   
      var   xmlhttp=new   ActiveXObject("Msxml2.xmlhttp")   
      xmlhttp.open("GET",window.location.href,false)   
      xmlhttp.send()   
      var   str   =   bytes2BSTR(xmlhttp.ResponseBody)   
      alert(str)   
      </script>
      

  3.   

    孟子E章的生成静态方法可以一试
    重写页面
    render预呈现事件
      

  4.   

    http://www.cnblogs.com/goody9807/category/112628.html
      

  5.   

    使用javascript获取网页内容 http://blog.csdn.net/hertcloud/archive/2007/03/26/1541532.aspx
    用以上的方法,自动返回该网站首页的源代码,我测试后不成功。
    以下为代码
    <HTML>
        <HEAD>
            <title>xmlhttp获取网页内容</title>
            <script language="javascript">
    function getXML(URL) 
    {
     var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        xmlhttp.Open("GET",URL, false);
        try { 
            xmlhttp.send(); 
           var result = xmlhttp.status;}
        catch(e) {return(false);}
      if(result==200) { 
          return(xmlhttp.responseText); 
                 }
       delete(xmlhttp)
     }
    function setData()

     try
     {
      document.getElementById("tbhome").innerText = getXML('http://www.9588.com/FlightTicket/query.aspx?StartCity=PEK&ArrivalCity=NKG&FlyDate=2009-04-08&FlyTime=00:00&AirCompany=');//+'?para='+Math.random());  
     }
     catch(e)
      {
       alert('在获取数据时出错!');
      }
    }
            </script>
        </HEAD>
        <body onload="setData();">
            <br>
            <p><br>
            </p>
            <form id="frmHome" method="post">
                <div align="center">
                    <textarea name="tbhome" rows="25" cols="80" id="tbhome"></textarea>
                </div>
            </form>
        </body>
    </HTML>
      

  6.   

    使用上面几楼提供的javascript方法和直接使用xmlhttprequest是一样的,肯定是站点对request加了路径认证!
      

  7.   

    路过,我记得有个System.Net.WebRequest可以获取一个指定url地址的页面的源文件
      

  8.   

    using System.Text;
    using Microsoft.Win32;
    using System.Security.Cryptography;private string PostWebRequest(string url,string postData)        
       {
        try
        {   
         //CookieContainer cc = new CookieContainer();
         //    string postData = "user=" + strUser + "&pass=" + strPsd;
         byte[] byteArray = Encoding.UTF8.GetBytes(postData); // 转化 免费资源http://www.it55.com     HttpWebRequest webRequest2 = (HttpWebRequest)WebRequest.Create(new Uri(url));
         //webRequest2.CookieContainer = cc;
         webRequest2.Method = "POST";
         webRequest2.ContentType = "application/x-www-form-urlencoded";
         webRequest2.ContentLength = byteArray.Length;
         Stream newStream = webRequest2.GetRequestStream();        // Send the data.
         newStream.Write(byteArray, 0, byteArray.Length);    //写入参数
         newStream.Close();     HttpWebResponse response2 = (HttpWebResponse)webRequest2.GetResponse();
         StreamReader sr2=new StreamReader(response2.GetResponseStream(), Encoding.Default);
         return sr2.ReadToEnd();   
        }
        catch 
        {
         return "-1";
        }
       }   =====================================================
     public string getPage(String url)
       {
        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";
         StringBuilder UrlEncoded = new StringBuilder();    
         req.ContentLength = 0;
         res = (HttpWebResponse)req.GetResponse();
         Stream ReceiveStream = res.GetResponseStream();
         Encoding encode = System.Text.Encoding.GetEncoding("gb2312");     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;
       }
      

  9.   

    在第一行 <%%> 里面加入validateRequest=false
      

  10.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="xxx.aspx.cs" Inherits="zhuqu"  ValidateRequest="false"%>
      

  11.   

    你的代码中。
    request.Method = "POST"; 这个明明是GET请求嘛。