预览模式: 普通 | 列表

Function GetWebCode(ByVal strURL As String) As String
Dim httpReq As System.Net.HttpWebRequest
Dim httpResp As System.Net.HttpWebResponse
Dim httpURL As New System.Uri(strURL)
Dim ioS As System.IO.Stream, charSet As String, tCode As String
Dim k() As Byte
ReDim k(0)
Dim dataQue As New Queue(Of Byte)
httpReq = CType(WebRequest.Create(httpURL), HttpWebRequest)
Dim sTime As Date = CDate("1990-09-21 00:00:00")
httpReq.IfModifiedSince = sTime
httpReq.Method = "GET"
httpReq.Timeout = 7000

Try
httpResp = CType(httpReq.GetResponse(), HttpWebResponse)
Catch
Debug.Print("weberror")
GetWebCode = "<title>no thing found</title>" : Exit Function
End Try
'以上为网络数据获取
ioS = CType(httpResp.GetResponseStream, Stream)
Do While ioS.CanRead = True
Try
dataQue.Enqueue(ioS.ReadByte)
Catch
Debug.Print("read error")
Exit Do
End Try
Loop
ReDim k(dataQue.Count - 1)
For j As Integer = 0 To dataQue.Count - 1
k(j) = dataQue.Dequeue
Next
'以上,为获取流中的的二进制数据
tCode = Encoding.GetEncoding("UTF-8").GetString(k) '获取特定编码下的情况,毕竟UTF-8支持英文正常的显示
charSet = Replace(GetByDiv2(tCode, "charset=", """"), """", "") '进行编码类型识别
'以上,获取编码类型
If charSet = "" Then 'defalt
If httpResp.CharacterSet = "" Then
tCode = Encoding.GetEncoding("UTF-8").GetString(k)
Else
tCode = Encoding.GetEncoding(httpResp.CharacterSet).GetString(k)
End If
Else
tCode = Encoding.GetEncoding(charSet).GetString(k)
End If
Debug.Print(charSet)
'Stop
'以上,按照获得的编码类型进行数据转换
'将得到的内容进行最后处理,比如判断是不是有出现字符串为空的情况
GetWebCode = tCode
If tCode = "" Then GetWebCode = "<title>no thing found</title>"
End Function

将如上代码复制,并引用:
Imports System.Net
Imports System.IO
Imports System.Text.Encoding
Imports System.Text

然后,就可以使用这个代码完成网页源代码下载的工作了。

Tags: vb.net

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 398

cefsharp 禁止图片加载

只需要添加一句话就可以实现此功能


chromeBrowser.BrowserSettings.ImageLoading = CefState.Disabled;

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 469

VB.net正则验证Email地址

 Imports System.Text.RegularExpressions
''' <summary>
''' 校验邮箱地址是否合法
''' </summary>
''' <param name="addr"></param>
''' <returns>合法返回True,不合法返回false</returns>
Public Function validateEmail(ByVal addr As String) As Boolean
Dim reg As New Regex("\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}")
Return reg.IsMatch(addr)
End Function

Tags: vb.net

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 455

vb.net 请求被中止: 未能创建 SSL/TLS

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 or SecurityProtocolType.Tls or SecurityProtocolType.Tls11 or SecurityProtocolType.Tls12
ServicePointManager.Expect100Continue = True

Tags: vb.net

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 337

 广告位

↑返回顶部↑