-
Apr 10th, 2006, 10:10 PM
#1
Thread Starter
Frenzied Member
VB6 To VB.NET (Winsock)
Here is my current function which uses a Winsock control (on a seperate form) to connect to a server, send an HTTP Request, and recieve/handle the returned data:
VB Code:
Public Function GetHTTP(htype As HTTPType, strUrl As String, Optional strcookie As String, Optional strrefer As String, Optional strData As String, Optional GZIP As Boolean = True) As String
Dim strServer As String
Dim strPage As String
Dim header As String
frmMain.sck1.Close
Connected = False
If InStr(1, strUrl, "http://") Then
strUrl = Replace(strUrl, "http://", "")
End If
iStart = InStr(6, strUrl, ".") + 4
strPage = Mid$(strUrl, iStart, (Len(strUrl) + 1) - iStart)
strServer = Replace(strUrl, strPage, "")
strPage = Replace(strPage, " ", "%20")
StrReturn = ""
frmMain.sck1.Connect strServer, 80
Do Until Connected = True Or frmMain.sck1.State = 9
DoEvents
Loop
If frmMain.sck1.State = 9 Then
MsgBox "Error connecting to server!"
frmMain.sck1.Close
Exit Function
End If
header = CreateHeader(htype, strServer, strPage, strcookie, strrefer, strData, GZIP) 'Creates an HTTP Request
frmMain.sck1.SendData header
Do Until frmMain.sck1.State = 8
DoEvents
Loop
lngPos = InStr(1, StrReturn, vbCrLf & vbCrLf)
If InStr(1, StrReturn, "text/html; charset=UTF-8" & vbNewLine & vbNewLine) Then
' Future Handle '
ElseIf StrReturn <> "" And GZIP = True Then
Strheader = Left(StrReturn, lngPos - 1)
StrReturn = Right$(StrReturn, Len(StrReturn) - lngPos - 3)
StrReturn = DecompressGzipData(StrReturn, LenB(StrReturn))
StrReturn = Strheader & vbNewLine & vbNewLine & StrReturn
End If
Connected = False
GetHTTP = StrReturn
glastpage = strUrl
frmMain.sck1.Close
End Function
I need to know the best method for doing what I did above in VB.NET. I know there are multiple ways of accessing the net through the language, but I prefer to stick with simple connecting to server, and retreiving data. Can anyone suggest the best method for doing this? And yes, I also need to handle GZIP Compressed data, in VB6 I have to use an external DLL, but I think it's possibly to do it internally in .NET.
Age - 15 ::: Level - Advanced
If you find my post useful please ::Rate It::
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|