vb.net如何使用HttpWebRequest模拟登陆带验证码的网站一般登陆网站时候首先要打开一个网页对吧?
那首先要 GET 一个网址 。GetResponse后,得到的流就是这个页面的源码 。
源码里肯定会包含这个验证码的提问段(可能是个图片的网址,也可能是个 5+5=? 之类的字符串之类的),可以分析一下这段代码出现的位置,让程序自动寻找 。找到这个图片的网址,把这个图片 GET 下来,然后,就是orc识别或你人工识别咯 。。。
用vb能否编写出一个自动获取和填写验证码的程序?Dim vCode As String
Private Sub Command1_Click()
drawvc
End Sub
Private Sub drawvc() '显示校验码
Dim i, px, py As Long, vc As String
Dim r, g, b As Byte
Randomize '初始化随机种子
'生成随机校验码
For i = 1 To 4
Do
num = Rnd() * 74 + 48
Loop While num48 Or (num57 And num65) Or (num90 And num97) Or num122
vc = vcChr(num)
Next i
vCode = vc
'显示校验码
Picture1.Cls
Picture1.Print vc
'添加噪点(防止自动图像识别)
For i = 0 To 2000 '画2000个噪点
'画点随机位置
px = CLng(Picture1.Width * Rnd)
py = CLng(Picture1.Height * Rnd)
'画点随机颜色
r = CByte(255 * Rnd)
g = CByte(255 * Rnd)
b = CByte(255 * Rnd)
Picture1.Line (px, py)-(px + 1, py + 1), RGB(r, g, b)
Next
End Sub
Private Sub Command2_Click()
If Text1.Text = vCode Then
MsgBox ("正确")
Else
MsgBox ("错误")
drawvc
End If
End Sub
Private Sub Form_Load()
Picture1.FontSize = 12
Picture1.FontBold = True
Picture1.AutoRedraw = True
drawvc
End Sub
求一个vb.net写的验证码?建一个YanzhenCard.aspx文件
保留%@ Page Language="VB" AutoEventWireup="false" CodeFile="YanzhenCard.aspx.vb" Inherits="YanzhenCard" %,其余删除
如下是代码:
Imports System.IO
Imports System.Drawing
Partial Class YanzhenCard
Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim VNum As String = GenerateRandom(4)
Session("VNum") = VNum
ValidateCode(VNum)
End If
End Sub
Private Sub ValidateCode(ByVal VNum As String)
Dim Gheight As Integer = CType((VNum.Length * 15), Integer)
Dim Img As Bitmap = New Bitmap(Gheight, 20)'Bitmap是用于处理由像素数据定义的图像
Dim g As Graphics = Graphics.FromImage(Img)'Graphics.FromImage 从指定的Image创建新的Graphics
g.DrawString(VNum, New Font("Arial", 12), New SolidBrush(Color.Red), 5, 0)'g.DrawString()在指定位置并且用指定的Brush和Font对象绘制指定的文本字符串 。
Dim ms As MemoryStream = New MemoryStream'创建其支持存储区为内存的流 。
Img.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
Response.ClearContent()
Response.ContentType = "image/PNG"
Response.BinaryWrite(ms.ToArray)
Response.Write(VNum)
g.Dispose()
Img.Dispose()
Response.End()
End Sub
Private Shared constant As Char() = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
Public Shared Function GenerateRandom(ByVal Length As Integer) As String
Dim newRandom As System.Text.StringBuilder = New System.Text.StringBuilder(26)
Dim rd As Random = New Random
Dim i As Integer = 0
While iLength
newRandom.Append(constant(rd.Next(26)))
System.Math.Min(System.Threading.Interlocked.Increment(i), i - 1)
End While
Return newRandom.ToString
End Function
End Class
调用方法:asp:ImageButton ID="Yanzhengma_Card" runat="server" ImageUrl="YanzhenCard.aspx" Height="20px" Width="75px" BorderColor="#6699cc" BorderStyle="Solid" BorderWidth="1px" /
推荐阅读
- 苏州跨境电商市场前景如何,苏州跨境电商运营公司排名
- python中new_用法,python _new_
- html图片自动滚动模板,html怎么让图片自动滑动
- 语音直播运营总监,直播运营总监有哪些要求
- java程序调用c代码 java调用c语言程序
- 出售废旧手机应该注意什么,出售旧手机有风险吗
- 军事模拟器游戏下载免费,军事模拟器2破解版
- boss直播斗鱼,斗鱼boss是谁
- 如何注册微信公众号并运行,怎么样注册公众微信号