0
我試圖使用HTTPWebRequets代理和它的工作就好了,直到我嘗試和發佈數據。由於某種原因它會保持超時。附加的是我用於webrequests的課程。有人可以請指教。代理與HTTPWebRequest和發佈
Imports System.IO
進口System.Net
公共類EasyHttp 公共枚舉列舉HTTPMethod短 HTTP_GET = 0 HTTP_POST = 1 結束枚舉 公共代理作爲字符串 公共端口作爲整數 公共UseProxy作爲整數= 0 Public Sub New() 'No Args構造函數 End Sub
Public Function Send(ByVal URL As String, _
Optional ByVal PostData As String = "", _
Optional ByVal Method As String = "", _
Optional ByVal ContentType As String = "")
Dim request As HttpWebRequest
request = WebRequest.Create(URL)
request.ServicePoint.Expect100Continue = False
Dim Response As HttpWebResponse
Dim SW As StreamWriter
Dim SR As StreamReader
Dim ResponseData As String
If UseProxy = 1 Then
request.Proxy = New WebProxy(Proxy, Port)
End If
' Prepare Request Object
request.Method = Method
' Set form/post content-type if necessary
If (Method = "POST" AndAlso PostData <> "" AndAlso ContentType = "") Then
ContentType = "application/x-www-form-urlencoded"
End If
' Set Content-Type
If (ContentType <> "") Then
request.ContentType = ContentType
request.ContentLength = PostData.Length
End If
' Send Request, If Request
If (Method = "POST") Then
' Try
SW = New StreamWriter(request.GetRequestStream())
SW.Write(PostData)
' Catch Ex As Exception
'Throw Ex
' Finally
'SW.Close()
' End Try
End If
' Receive Response
' Try
Response = request.GetResponse()
SR = New StreamReader(Response.GetResponseStream())
ResponseData = SR.ReadToEnd()
' Catch Wex As System.Net.WebException
' SR = New StreamReader(Wex.Response.GetResponseStream())
' ResponseData = SR.ReadToEnd()
' Throw New Exception(ResponseData)
' Finally
' SR.Close()
' End Try
Return ResponseData
End Function
結束類別