当前位置:编程学习 > C#/ASP.NET >>

关于HttpWebRequest登陆的问题。

模拟登陆始终不成功。
大家看我发送的数据
string postData = "userName=1111&userPass=1111&uuid=" + "&verifyCode=" + txt_img.Text + "&uuid=" + uuid;
这个uuid 不知道是个什么值,我就直接给了他一个 Guid的值(根据抓包工具得到的结果确认他是个guid)
现在,用户名,密码,验证码都是明确能知道来源的,就是这个uuid不知道是怎么得到的,
请问我应该用什么方法获得呢?
HttpWebRequest --------------------编程问答-------------------- 我觉得是verifyCode的问题,验证码你是否给正确了?那个uuid应该是和验证码绑定的,也就是说,它给你验证码图片的时候,同时给你一个uuid值,你通过返回uuid值,来确定是哪个图片对应的验证码内容。 --------------------编程问答-------------------- 漏掉了个重要的信息
<input id="verifyCode" placeholder="验证码" type="text" class="common-text" name="verifyCode" autocomplete="off" maxlength="4">
<img id="imgObj" src="verifyCodeServlet?uuid=7d6a3d47-44a5-4099-a2c3-7932f9eec84e"  
这里验证码图片地址有uuid的值。我在程序中 请求验证码的时候给他赋了个Guid的值。然后保留这个值到提交时用也没作用。

在他登陆的页面中有这么个函数
//为了使每次生成图片不一致,即不让浏览器读缓存,所以需要加上时间戳  
function chgUrl(url){  
     var timestamp = (new Date()).valueOf(); 
         url = url + "/tamp=" + timestamp; 
     return url;  
 } 
function changeImg(){
var imgSrc = $("#imgObj");  
    var src = imgSrc.attr("src").substr(0,59);  
    imgSrc.attr("src",chgUrl(src));  
}  
难道我还要调用它的函数来获取地址值吗? --------------------编程问答-------------------- 我觉得是verifyCode的问题 --------------------编程问答-------------------- 一般遇到这种情况应该怎么做呢?
http://abc.com/verifyCodeServlet?uuid=818a2612-5acc-499c-a9d5-57574ab86fcf
这个地址每访问一次获取的验证码都不一样。问题应该出在这里。 --------------------编程问答-------------------- 希望大家关注一下 --------------------编程问答-------------------- 参考下这个实现:http://www.cnblogs.com/hoholuo/archive/2011/12/17/2290873.html --------------------编程问答--------------------
引用 2 楼 l0f 的回复:
漏掉了个重要的信息
<input id="verifyCode" placeholder="验证码" type="text" class="common-text" name="verifyCode" autocomplete="off" maxlength="4">
<img id="imgObj" src="verifyCodeServlet?uuid=7d6a3d47-44a5-4099-a2c3-7932f9eec84e"  
这里验证码图片地址有uuid的值。我在程序中 请求验证码的时候给他赋了个Guid的值。然后保留这个值到提交时用也没作用。

在他登陆的页面中有这么个函数
//为了使每次生成图片不一致,即不让浏览器读缓存,所以需要加上时间戳  
function chgUrl(url){  
     var timestamp = (new Date()).valueOf(); 
         url = url + "/tamp=" + timestamp; 
     return url;  
 } 
function changeImg(){
var imgSrc = $("#imgObj");  
    var src = imgSrc.attr("src").substr(0,59);  
    imgSrc.attr("src",chgUrl(src));  
}  
难道我还要调用它的函数来获取地址值吗?

你给的信息太少,这两个函数哪里被调用都看不到,网站地址也没给,很难分析他是如何切换图片的。 --------------------编程问答-------------------- qldsrx,你好!
我找到了他uuid的信息了,就在登陆页面中有个隐藏字段。
httpWebRequest后得到的网页后有如下内容:

<p class="common-captcha" id="captcha" style="margin-top:10px">
<input type="hidden" id="uuid" name="uuid" value="7d6a3d47-44a5-4099-a2c3-7932f9eec84e" />
<input id="verifyCode" placeholder="验证码" type="text" class="common-text" name="verifyCode" autocomplete="off" maxlength="4">
<img id="imgObj" src="verifyCodeServlet?uuid=7d6a3d47-44a5-4099-a2c3-7932f9eec84e" width="100" height="50"> <a href="javascript:" onclick="changeImg()"><span style="height:50">换一张</span></a>
        </p>

我用如下代码还是不能正确登陆。 其中 txt_img.Text 是上面的uuid内容,txt_img.Text 是访问
verifyCodeServlet?uuid=7d6a3d47-44a5-4099-a2c3-7932f9eec84e 后得到的验证码信息。

string uriString = "http://xxx.xxx.com/xxx/login.action";
string postData = "userName=myname&userPass=000000&uuid=" + "&verifyCode=" + txt_img.Text + "&uuid=" + txt_Uuid.Text;
HttpHelper httpHelper = new HttpHelper();
this.webBrowser_Main.DocumentText = httpHelper.PostDataToString(uriString,postData, ref nowCookies);
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,