利用 HttpWebRequest ,HttpWebResponse
Post 數據 順便取原始碼的 自訂函數
Public Function PostData_Get_Cookie(ByRef URL As String, ByRef POST As String) As String
Dim MyHttpRequest As HttpWebRequest
Dim MyHttpResponse As HttpWebResponse
Dim MyReqStream As Stream
Dim PostBytes As Byte()
Dim MyCookie As New CookieContainer
Dim MySR As IO.StreamReader
Dim MyStrText As String
MyHttpRequest = HttpWebRequest.Create(URL)
MyHttpRequest.Method = "POST"
MyHttpRequest.KeepAlive = True
MyHttpRequest.Timeout = 10000 '等待時間
MyHttpRequest.ContentType = "application/x-www-form-urlencoded"
MyHttpRequest.Referer = URL
MyHttpRequest.CookieContainer = MyCookie
'避免掉 417 錯誤
MyHttpRequest.ServicePoint.Expect100Continue = False
PostBytes = Encoding.ASCII.GetBytes(POST)
MyHttpRequest.ContentLength = PostBytes.Length
MyReqStream = MyHttpRequest.GetRequestStream
MyReqStream.Write(PostBytes, 0, PostBytes.Length)
MyHttpResponse = MyHttpRequest.GetResponse()
MySR = New StreamReader(MyHttpResponse.GetResponseStream, Encoding.Default)
MyStrText = MySR.ReadToEnd
MyReqStream.Close()
MyHttpResponse.Close()
Return MyStrText
End Function
留言列表