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
你是获取红色部分吗? 其他两个参数没有值为什么还传(不过对你这个取值参数没有影响)。 if (Request.QueryString["txtLName"] != null)
{
string LastName = Request.QueryString["txtLName"].ToString();
}应该可以取到的。 搜索时候记得要获取值。
URL搞的这么长。 不要传乱起八糟的东西,URL值传必要的没安全隐患的值。
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