网站内容调用
要实现一个调用另一个网站(a网站)的内容的功能,比如汽车票查询,a网站是一个表单提交来做的,就是输入城市 然后提交后 显示查询的数据。现在要把汽车票查询后的结果显示到我自己的网站上,用asp.net 怎么实现?自己写的代码如下,只能抓取到网站本身的内容,不能取到表单提交后的内容
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(payload);
url += "?" + payload;
//HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(" http://222.186.88.118:8081/wsdg_zjjt/ctsBusSearch.do" + "?" + payload);
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
//下面是解析,可以不用关注
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.Default);
string content = reader.ReadToEnd();
content = "<table width='90%' align='center' cellpadding='0' cellspacing='1' bordercolor='#e2f0ff' bgcolor='#e2f0ff'> <tr align=center valign=middle bgcolor='#e2f0ff'><td >" + Regex.Match(content, @"上车站(.|[^.])*?</[Tt][Aa][Bb][Ll][Ee][^>]*>").ToString();
content = content.Replace("td", "td height='24'");
content = content.Replace("COLSPAN=18", " height='24' COLSPAN='8'");
return content;
--------------------编程问答-------------------- 没人会么 --------------------编程问答-------------------- 检查你的payload的内容,要素有没有全?
另:lz的头像是凤凰的珊玲MM
? --------------------编程问答-------------------- 用“流”读取网页内容然后传参试试 --------------------编程问答-------------------- 抓包分析
httpwebrequest
post
string param = "";
byte[] bs = Encoding.ASCII.GetBytes(param);
HttpWebRequest req = (HttpWebRequest) HttpWebRequest.Create( "" );
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = bs.Length;
using (Stream reqStream = req.GetRequestStream())
{}
补充:.NET技术 , ASP.NET