Imports System
Imports System.Text
Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports Microsoft.VisualBasic
''' <summary>
''' 实现向web发送和接收数据的类
''' </summary>
''' <remarks></remarks>
Public Class WebClient
Const BOUNDARY As String = "--HEDAODE--"
Const SEND_BUFFER_SIZE As Integer = 8000
Const RECEIVE_BUFFER_SIZE As Integer = 15000
Dim _strUrl, _strTextField, _strFileField As String
Dim method, contentType, host, path, _headerText, _respHtml, _referer, _cookie As String
Public Encode As Encoding = Encoding.Default
Dim r As RegularExpressions.Regex
Dim m As RegularExpressions.Match
Dim PostDataList()(), header() As Byte
Dim _start As Boolean = True
Dim _SendProgress, _ReceiveProgress, _SendContentLength, _ReceiveContentLength, startIndex As Integer
''' <summary>
''' 请求的url地址
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Property strUrl() As String
Get
Return _strUrl
End Get
Set(ByVal value As String)
If value <> "" Then
m = r.Match(value, "https*://([^/]+)(/(.+))?")
If m.Success Then
host = m.Groups(1).Value
path = "/" + m.Groups(3).Value
_strUrl = value
Else
MsgBox("URL不合法!")
End If
End If
End Set
End Property
''' <summary>
''' 要发送的文本域
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Property strTextField() As String
Get
Return _strTextField
End Get
Set(ByVal value As String)
If value <> "" Then
m = r.Match(value, "(/w+=[^&]+)|((/w+=[^&]+&)+)")
If m.Success Then
_strTextField = value
Else
MsgBox("数据有误:" & value)
End If
End If
End Set
End Property
''' <summary>
''' 要发送的文件域
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Property strFileField() As String
Get
Return _strFileField
End Get
Set(ByVal value As String)
If value <> "" Then
m = r.Match(value, "(/w+=[^&]+)|((/w+=[^&]+&)+)")
If m.Success Then
_strFileField = value
Else
MsgBox("数据有误:" & value)
End If
End If
End Set
End Property
''' <summary>
''' 获取或设置Cookie
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks>用来跟踪用户身份</remarks>
Property Cookie() As String
Get
Return _cookie
End Get
Set(ByVal value As String)
_cookie = value
End Set
End Property
''' <summary>
''' 获取或设置Referer
''' </summary>
''' <value></value&g