来源页面: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());
}
在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());
}
解决方案 »
- 只有在配置文件或 Page 指令中将 enableSessionState 设置为 true 时,才能使用会话状态。
- 我是新手,问大家关于新闻首页的问题?
- 请教一个转义字符的问题!
- 怎样向treeview的子节点中添加节点?????????
- 呼叫.net iis老手!!关于tree 框架 页面跳转 iis连接数 页面资源
- 如何读取记事本文件内容
- 【散分求好书推荐!】好书追加给分哦.
- freetextbox如何自动抓取远程图片本地保存?
- vs.net不能添加新的对象!在线等待?
- 写一个后端方法SumNummber(),计算累加input中index='b'的元素的值,并反复结果
- 如何让一个表的两列合并显示?
- 项目发布后,asax应用程序生成dll文件,但是放到服务器上,asax却不起作用
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>
重写页面
render预呈现事件
用以上的方法,自动返回该网站首页的源代码,我测试后不成功。
以下为代码
<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>
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;
}
request.Method = "POST"; 这个明明是GET请求嘛。