如何用httpWebRequest自动注册,并填写图片识别码
一、图片识别码
Dim httpReq As System.Net.HttpWebRequest
Dim httpResp As System.Net.HttpWebResponse
Dim strBuff As String
Dim httpURL As New System.Uri("http://yourUrl.img.php?str=46203") 这是识别码图片的地址,你要换成你的地址
httpReq = CType(WebRequest.Create(httpURL), HttpWebRequest)
httpResp = CType(httpReq.GetResponse(), HttpWebResponse)
httpReq.KeepAlive = True 保持链接,你就一直可以用这个识别码了
strBuff = "CharacterSet: " & httpResp.CharacterSet.ToString & ControlChars.CrLf
strBuff = strBuff & "ContentEncoding: " & httpResp.ContentEncoding.ToString & ControlChars.CrLf
strBuff = strBuff & "ContentLength: " & httpResp.ContentLength.ToString & ControlChars.CrLf
strBuff = strBuff & "ContentType: " & httpResp.ContentType.ToString & ControlChars.CrLf
strBuff = strBuff & "LastModified: " & httpResp.LastModified.ToString & ControlChars.CrLf
strBuff = strBuff & "Method: " & httpResp.Method.ToString & ControlChars.CrLf
strBuff = strBuff & "ProtocolVersion: " & httpResp.ProtocolVersion.ToString & ControlChars.CrLf
strBuff = strBuff & "ResponseUri: " & httpResp.ResponseUri.ToString & ControlChars.CrLf
strBuff = strBuff & "Server: " & httpResp.Server.ToString & ControlChars.CrLf
strBuff = strBuff & "StatusCode: " & httpResp.StatusCode.ToString & ControlChars.CrLf
strBuff = strBuff & "StatusDescription: " & httpResp.StatusDescription.ToString & ControlChars.CrLf
httpReq.Method = "GET"
MsgBox(strBuff)
二、自动注册
Dim httpUrl2 As New System.Uri("http://yourUrl/cgi-bbs/signup.cgi?" & "bookname=1®id=1&str=1&userid=459&password=1&confirm=1&username=1&cardnumber=1") 在地址后挂上你要注册的信息,什么用户名密码什么的
Dim req As HttpWebRequest
req.Timeout = 10000 超时5秒
req = CType(WebRequest.Create(httpUrl2), HttpWebRequest)
req.Method = "POST"
req.ContentType = "application/x-www-form-urlencoded" ’这句一定要
Dim bytesData() As Byte = System.Text.Encoding.ASCII.GetBytes("bookname=1®id=1&str=1&userid=459&password=1&confirm=1&username=1&cardnumber=1") ‘把注册信息转换在字节
req.ContentLength = bytesData.Length ’注册信息的长度
Dim postStream As Stream = req.GetRequestStream()
postStream.Write(bytesData, 0, bytesData.Length)
postStream.Close()
Dim res As HttpWebResponse = CType(req.GetResponse(), HttpWebResponse)
MsgBox(res.StatusCode.ToString)
Dim enc As Encoding = System.Text.Encoding.GetEncoding("GB2312")
Dim sPostData As String = "content=" & HttpUtility.UrlEncode(sContent, enc) & "&name=" & HttpUtility.UrlEncode(sName, enc) ‘如果有中文的内容,可能要用到这句