比如要查询在上海的交通违章(http://www.shjtaq.com/Server3/dzjc_new.asp),我想把车牌号、发动机号在页面跳转后直接显示,我只要输入验证码,点击提交按钮就能查询了
解决方案 »
- 关于GridView控件行变色的问题
- 这是一个问题标题要长长长长长长长长长长长长长长
- jquery easyui tree 点击不同节点加载不同json页面
- 请教一个读取文件速度的问题
- 如何从数据库里调用图片?
- 工具箱中没有Anchor控件,从添加/删除控件里面选择哪项添加?
- win2003 + iis6服务器上web程序(.net framework3.5)session失效
- ASP.NET的进一步提高
- 请问是不是用codebehind写的aspx文件在租的服务器上不能运行
- 一次檢索出DataSet數據存至Session還是每次DataGrid翻頁時檢索為好?
- 服务器.net组件不支持
- 关于生成字符串的算法?
如果没有验证码,直接用HttpWebRequest发送post请求过去就行了。
有验证码就麻烦一些,因为验证码的字符串应该是用session记录的,而HttpWebRequest发送请求在不指定sessionid的情况下每次请求产生的sessionid都会不同,被认为是不同的请求。所以在使用HttpWebRequest时需要指定sessionid,把对方网站的验证码页面请求过来,查看过那个页面源码,验证码的链接是http://www.shjtaq.com/Server3/validatecode.asp?m=83303.77,让自己网站的使用者把查询需要的数据,以及验证码填好再把数据用HttpWebRequest发送post请求指定同样的sessionid发送到对放服务器进行查询,最后分析返回数据的获得自己需要的结果。
如果对sessionid不了解建议先去了解一下。
#region 获取html数据流
/// <summary>
///
/// </summary>
/// <param name="url">请求的url</param>
/// <param name="RefererUrl">发起请求的页面</param>
/// <param name="Method">请求的方法post/get</param>
/// <param name="Cookie">请求时附带的cookies</param>
/// <param name="PostStr">post过去的信息</param>
/// <param name="GetRedirect">是否获取重定向后的内容</param>
/// <param name="response">回传response参数</param>
public static void Get_Response(string url, string RefererUrl, string Method, ref CookieCollection Cookie, string PostStr, bool GetRedirect, ref HttpWebResponse response)
{
HttpWebRequest request = null;
try
{
//myjob需要
System.Net.ServicePointManager.Expect100Continue = false;
//myjob需要
request = (HttpWebRequest)WebRequest.Create(url);
request.UserAgent = UserAgent;
request.Timeout = 20000;
request.AllowAutoRedirect = GetRedirect;
request.Method = Method;
if (RefererUrl != "")
{
request.Referer = RefererUrl;
}
if (Cookie != null)
{
request.CookieContainer = new CookieContainer();
request.CookieContainer.Add(Cookie);
}
if (Method == "POST")
{
request.ContentType = "application/x-www-form-urlencoded"; //作为表单请求
if (PostStr != "")
{
Byte[] B = System.Text.Encoding.UTF8.GetBytes(PostStr);
request.ContentLength = B.Length;
Stream SW = request.GetRequestStream(); //开始提交数据
SW.Write(B, 0, B.Length);
SW.Close();
}
}
response = (HttpWebResponse)request.GetResponse();
}
catch
{
} finally
{
if (request != null)
request = null;
} }
#endregion