Results 1 to 4 of 4

Thread: Winsock Cryptic Error :|

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Location
    Manchester
    Posts
    266

    Winsock Cryptic Error :|

    Hi,

    I have run across a strange problem when trying to request a webpage using winsock. Any help would be useful. My code is as follows:

    VB Code:
    1. Dim Url() As String
    2.  
    3. Public Sub beginana_Click(index As Integer)
    4. Dim loop As Integer
    5.  
    6. 'Contains a list of URL's
    7. ReDim Url(urlq.ListCount) As String
    8.  
    9. For loop = 0 To urlq.ListCount
    10. Url(loop) = urlq.List(loop)
    11. Next loop
    12.  
    13. 'Call process and send zero to addloc
    14. process(0)
    15. End Sub
    16.  
    17. Private Sub process(addloc As Single)
    18.  
    19.     With mainfrm.mkt
    20.         .Close
    21.         .LocalPort = 0
    22.     End With
    23.    
    24.     'Set address to be worked upon (workind is a global string in module       ' 'UrlList)
    25.     UrlList.workind = addloc
    26.     'Set the remote host/port
    27.     mkt.RemoteHost = Url(addloc)
    28.     mkt.RemotePort = 80
    29.     mkt.Connect
    30.    
    31. End Sub
    32.  
    33. Private Sub mkt_Connect()
    34. MsgBox ("")
    35.     packet = "GET / HTTP/1.1" & vbNewLine
    36.     packet = packet & "Host: " & Mid(Url(UrlList.workind), 8, Len(Url(UrlList.workind)) - 7) & vbNewLine
    37.     'Add packet terminator
    38.     packet = packet & vbNewLine
    39.    
    40.     'Send data request
    41.     mkt.SendData (packet)
    42. End Sub

    The msgbox never fires and the following error occurs:

    11004 Valid name, no data record of requested type -2146817284 C:\WINDOWS\system32\MSWINSCK.OCX 0

    On debugging Url(addloc) = "http://www.google.co.uk" and Mid(Url(UrlList.workind), 8, Len(Url(UrlList.workind)) - 7) = "www.google.co.uk" (which is how it should be).

    Does anyone have any ideas of what i'm doing wrong?

    Jord

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Winsock Cryptic Error :|

    Which line generates the error? Most of us are too old for our telepathy to work.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Location
    Manchester
    Posts
    266

    Re: Winsock Cryptic Error :|

    Quote Originally Posted by Al42
    Which line generates the error? Most of us are too old for our telepathy to work.
    If I knew that - I wouldn't have such a problem. The error is a winsock error and is not 'generated' by any one particular line of code as far as I can see.
    This is the problem, I need a second pair of eyes to find where the problem may be.

  4. #4
    Junior Member Mackster's Avatar
    Join Date
    Apr 2005
    Posts
    24

    Re: Winsock Cryptic Error :|

    Hi,
    Ok for the first problem
    Ur function Url(addloc) = "http://www.google.co.uk" should return
    www.google.co.uk and not the Http:// that is what is generating the error, I think due to the fact that Winsock does not know that u are using HTTP Protocol to communicate, and does not know how to handle the remote to be http://www.google.co.uk, but is fine when you only pass it www.google.co.uk as

    Code:
        mkt.Protocol = sckTCPProtocol
        mkt.RemoteHost = "www.google.co.uk"
        mkt.RemotePort = 80
        mkt.Connect
    Maybe trying something different might help, here is how you can use MSXML to do the same thing. Even though you can use this for XML data, but it can be used for normal HTTP operations also.
    P.S. you can run it in both sync and async see MSDN for both complete examples.
    Code:
        Dim myHTTP
        Dim HTTPUrl As String
        Dim HTTPData As String
        
        HTTPUrl = "http://www.google.com"
        
        Set myHTTP = CreateObject("Msxml2.XMLHTTP")
            myHTTP.Open "GET", HTTPUrl, False
            myHTTP.setRequestHeader "Cache-Control", "no-cache"
            myHTTP.setRequestHeader "Accept-Language", "it"
            myHTTP.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
            myHTTP.Send
            On Error Resume Next
            If Err.Number <> 0 Then
                HTTPData = "Bad URL"
            Else
                HTTPData = myHTTP.responsetext
            End If
        Set myHTTP = Nothing
        Debug.Print HTTPData
    Hope this helps, also to post the data, its the same.

    Code:
        Dim SendData 
        Dim myHTTP
        Dim HTTPUrl As String
        Dim HTTPData As String
        
        HTTPUrl = "http://www.google.com"
        
        Set myHTTP = CreateObject("Msxml2.XMLHTTP")
            myHTTP.Open "POST", HTTPUrl, False
            myHTTP.setRequestHeader "Cache-Control", "no-cache"
            myHTTP.setRequestHeader "Accept-Language", "it"
            myHTTP.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
            myHTTP.Send SendData 
            On Error Resume Next
            If Err.Number <> 0 Then
                HTTPData = "Bad URL"
            Else
                HTTPData = myHTTP.responsetext
            End If
        Set myHTTP = Nothing
        Debug.Print HTTPData

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width