https://extranet.in.gov/PhoneDirectory/EmpSearch.aspx, 我在"Last Name"输入"mac", 会返回所有带"mac"的名字; 我想把这个url换成https://extranet.in.gov/PhoneDirectory/EmpSearch.aspx?txtFName=&txtLName=mac&ddlAgencies=%, 就得不到任何搜索结果了。弱问下在后面这个url里面我是不是缺了什么变量/参数?多谢哈!另外一个例子是http://www.alaska.gov/whitepages/default.aspx,也是搞不定,试的是http://www.alaska.gov/whitepages/default.aspx?ctl00$cphBody$txtName=mac&ctl00$cphBody$txtTitle=&ctl00$cphBody$txtSearchPhone=&ctl00$cphBody$ddlAgency=&ctl00$cphBody$txtAddress=&ctl00$cphBody$txtPcnJccBu=&ctl00$cphBody$btnSearch=Searchaspx

解决方案 »

  1.   

    https://extranet.in.gov/PhoneDirectory/EmpSearch.aspx?txtFName=&txtLName=mac&ddlAgencies=%
    你是获取红色部分吗? 其他两个参数没有值为什么还传(不过对你这个取值参数没有影响)。            if (Request.QueryString["txtLName"] != null)
                {
                    string LastName = Request.QueryString["txtLName"].ToString();
                }应该可以取到的。 搜索时候记得要获取值。
      

  2.   

    你为什么要用这么乱七八糟这么长的字符 做参数名?ctl00$cphBody$txtName
    URL搞的这么长。 不要传乱起八糟的东西,URL值传必要的没安全隐患的值。 
      

  3.   

    这些乱七八糟的参数是这个网站的:http://www.alaska.gov/whitepages/default.aspx,我只是想加回到url里看看能不能同样获得结果。为啥这些都取出来还是跟直接输入然后搜索不一样呢?
      

  4.   

    这个网站搜索用的是POST提交数据的方式,而非GET,你可以利用WebRequest方式来模拟他的请求,而非通过地址栏
      

  5.   

    这个WebRequest怎么模拟呢?能不能给个例子?叩谢!
      

  6.   

    https://extranet.in.gov/PhoneDirectory/EmpSearch.aspx?txtFName=&txtLName=mac&ddlAgencies=%  这样是不行的,URL里面是Get的参数.网页并不接收.Post可以使用类似的代码
    HttpWebRequest httpWReq =
        (HttpWebRequest)WebRequest.Create("http://domain.com/page.aspx");ASCIIEncoding encoding = new ASCIIEncoding();
    string postData = "username=user";
    postData += "&password=pass";
    byte[] data = encoding.GetBytes(postData);httpWReq.Method = "POST";
    httpWReq.ContentType = "application/x-www-form-urlencoded";
    httpWReq.ContentLength = data.Length;using (Stream stream = httpWReq.GetRequestStream())
    {
        stream.Write(data,0,data.Length);
    }HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
    不过返回的页面内容:responseString, 你要自己解析.代码来自
    http://stackoverflow.com/questions/4015324/http-request-with-post