Extract remoteHost, and URL from a header (WinSock)

Im working with a winsock control at the moment, and was hoping you could take a minute to let me know if this is the right way to extract the remote host, and url path from a winsock header file (im taking in the first 255 bytes - i think this would cover the header + urls)

I would appreciate it if you could let me know if theres anything wrong with it

Private Sub Incomming_DataArrival(Index As Integer, ByVal bytesTotal As Long)
On Error Resume Next
'Dim data as String


'would this be the header?
Incomming(Index).GetData Var.incomingData, 0, 255

If (Len(Var.incomingData) > 0) Then

''just need to use this to extract the site url etc..
''it goes through all bytes till it finds the pattern
For i% = 1 To Len(Var.incomingData)
If Mid(Var.incomingData, i%, 2) = "//" Then
'The website starts after the //(HTTP://)
Exit For
End If
Next
'here we want the url, path, and port if possible
'm_strRemoteHost = Left$(strURL, InStr(1, strURL, "/") - 1)
'm_strFilePath = Mid$(strURL, InStr(1, strURL, "/"))

For y% = i% + 2 To Len(Var.incomingData)
If Mid(Var.incomingData, y%, 1) = "/" Then
'The website ends at the /(www.tr.com/)
'In the case of www.tr.com/Junk/Cheese.html ,
'the /junk/Cheese.html is part of the request, not part of
'the website URL, so we connect to the website URL and send the request.

URL = Mid(Var.incommingData, i% + 2, y% - (i% + 2))
URLPath = Mid(Var.incomingData, y%, Len(Var.incomingData) - y%)
Exit For
End If

downloadUrlToString URL, URLPath, 81, temp 'this method uses downloaderLib
Append Var.incomingData, temp
End If


IncommingConns(Index).ReceivedData = Var.incomingData
RaiseEvent FowaredRequest(Index, i_Outgoing, IncommingConns(Index).ReceivedData)
End Sub

Comments

  • [b][red]This message was edited by Bulgarian_VB at 2005-8-13 13:16:0[/red][/b][hr]
    First of all, there's no such thing as a WinSock header file. WinSock has absolutely no integration with or awareness of HTTP.

    What you need to do first, is look around (Google will do) for RFC on the HTTP 1.1 protocol. It describes in detail what the HTTP headers contain, both for HTTP request (client to server) and HTTP response (server to client), and how exatcly it is formatted. I suppose you at the client side, although it's not very clear.

    Suggestion: Don't read only 255 bytes, read at least 1K to make sure you campture the entire HTTP header.

    Hope I helped,
    Nikolay Semov



  • : 'would this be the header?
    : Incomming(Index).GetData Var.incomingData, 0, 255

    Unless I'm mistaken, a "header" in HTTP is any line after the request or response code and before the body. Any given HTTP request/response can have many headers.

    : 'The website ends at the /(www.tr.com/)
    : 'In the case of www.tr.com/Junk/Cheese.html ,
    : 'the /junk/Cheese.html is part of the request, not part of
    : 'the website URL, so we connect to the website URL and send the request.

    I think you are confusing terms. "http://www.tr.com/Junk/Cheese.html" is a URL. It is composed of various other parts, like a protocol scheme (http), a domain name (www.tr.com), and a path (/Junk/Cheese.html).


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • Hi
    Thanks for your replies, I wasnt confused, but have managed to sort out what I was trying to do.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories