T
Tom
Hi, Could someone please help me with this
I am trying to do use the following code to post a form and get
response but it 's keep giving me a error "The operation has
timed-out." on this line
oRespons = CType(oRequest.GetResponse(), HttpWebResponse)
I have to us Unicode Encoding so it knows national charactor.
Please help how can i make this work
here is the code
Public Function DoHttpRequest(ByVal strWWWAddress As String, ByVal
strdata As String, ByRef strResult As String, ByRef iStatusCode As
HttpStatusCode) As Boolean
Dim bolReturn As Boolean
Dim strMethodName As String
strResult = ""
iStatusCode = HttpStatusCode.Unused
Dim timeRequestStart As DateTime = DateTime.Now
Dim oRequest As HttpWebRequest = Nothing
Dim oInStream As Stream = Nothing
Dim oRespons As HttpWebResponse = Nothing
Dim readStream As StreamReader = Nothing
Dim oEncoding As Encoding = Encoding.Unicode
Try
Dim bSendData As Boolean
strMethodName = "POST"
oRequest = CType(WebRequest.Create(strWWWAddress),
HttpWebRequest)
oRequest.Method = strMethodName
oRequest.ContentType = "application/x-www-form-urlencoded"
oRequest.ServicePoint.Expect100Continue = False
oRequest.Timeout = 10 * 1000
' oRequest.Credentials = New NetworkCredential("UserName",
"Password")
oRequest.ServicePoint.ConnectionLimit = 15
If bSendData Then
oInStream = oRequest.GetRequestStream()
Dim data As Byte() = oEncoding.GetBytes(strdata)
oInStream.Write(data, 0, data.Length)
oInStream.Flush()
oInStream.Close()
oInStream = Nothing
End If
oRespons = CType(oRequest.GetResponse(), HttpWebResponse)
readStream = New StreamReader(oRespons.GetResponseStream(),
Encoding.Unicode)
strResult = readStream.ReadToEnd()
readStream.Close()
readStream = Nothing
iStatusCode = oRespons.StatusCode
oRespons.Close()
oRespons = Nothing
bolReturn = True
Catch ex As Exception
' Me.EmailAdmin(ex.Message, ex.StackTrace)
'bolReturn = False
Finally
If Not (oInStream Is Nothing) Then
oInStream.Close()
End If
If Not (readStream Is Nothing) Then
readStream.Close()
End If
If Not (oRespons Is Nothing) Then
oRespons.Close()
End If
End Try
Return bolReturn
End Function 'DoHttpRequest
to call this function
in form_load
Dim param As Byte() =
HttpContext.Current.Request.BinaryRead(HttpContext.Current.Request.ContentLength)
Dim ps As String = Encoding.Unicode.GetString(param)
ps += "&cmd=_notify-validate"
Dim status As System.Net.HttpStatusCode
If DoHttpRequest("https://www.paypal.com/cgi-bin/webscr",
ps, strResponse, status) = False Then
' do insert to DB
end if
I am trying to do use the following code to post a form and get
response but it 's keep giving me a error "The operation has
timed-out." on this line
oRespons = CType(oRequest.GetResponse(), HttpWebResponse)
I have to us Unicode Encoding so it knows national charactor.
Please help how can i make this work
here is the code
Public Function DoHttpRequest(ByVal strWWWAddress As String, ByVal
strdata As String, ByRef strResult As String, ByRef iStatusCode As
HttpStatusCode) As Boolean
Dim bolReturn As Boolean
Dim strMethodName As String
strResult = ""
iStatusCode = HttpStatusCode.Unused
Dim timeRequestStart As DateTime = DateTime.Now
Dim oRequest As HttpWebRequest = Nothing
Dim oInStream As Stream = Nothing
Dim oRespons As HttpWebResponse = Nothing
Dim readStream As StreamReader = Nothing
Dim oEncoding As Encoding = Encoding.Unicode
Try
Dim bSendData As Boolean
strMethodName = "POST"
oRequest = CType(WebRequest.Create(strWWWAddress),
HttpWebRequest)
oRequest.Method = strMethodName
oRequest.ContentType = "application/x-www-form-urlencoded"
oRequest.ServicePoint.Expect100Continue = False
oRequest.Timeout = 10 * 1000
' oRequest.Credentials = New NetworkCredential("UserName",
"Password")
oRequest.ServicePoint.ConnectionLimit = 15
If bSendData Then
oInStream = oRequest.GetRequestStream()
Dim data As Byte() = oEncoding.GetBytes(strdata)
oInStream.Write(data, 0, data.Length)
oInStream.Flush()
oInStream.Close()
oInStream = Nothing
End If
oRespons = CType(oRequest.GetResponse(), HttpWebResponse)
readStream = New StreamReader(oRespons.GetResponseStream(),
Encoding.Unicode)
strResult = readStream.ReadToEnd()
readStream.Close()
readStream = Nothing
iStatusCode = oRespons.StatusCode
oRespons.Close()
oRespons = Nothing
bolReturn = True
Catch ex As Exception
' Me.EmailAdmin(ex.Message, ex.StackTrace)
'bolReturn = False
Finally
If Not (oInStream Is Nothing) Then
oInStream.Close()
End If
If Not (readStream Is Nothing) Then
readStream.Close()
End If
If Not (oRespons Is Nothing) Then
oRespons.Close()
End If
End Try
Return bolReturn
End Function 'DoHttpRequest
to call this function
in form_load
Dim param As Byte() =
HttpContext.Current.Request.BinaryRead(HttpContext.Current.Request.ContentLength)
Dim ps As String = Encoding.Unicode.GetString(param)
ps += "&cmd=_notify-validate"
Dim status As System.Net.HttpStatusCode
If DoHttpRequest("https://www.paypal.com/cgi-bin/webscr",
ps, strResponse, status) = False Then
' do insert to DB
end if