|
-
Jun 5th, 2006, 10:23 AM
#1
Thread Starter
Hyperactive Member
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:
Dim Url() As String
Public Sub beginana_Click(index As Integer)
Dim loop As Integer
'Contains a list of URL's
ReDim Url(urlq.ListCount) As String
For loop = 0 To urlq.ListCount
Url(loop) = urlq.List(loop)
Next loop
'Call process and send zero to addloc
process(0)
End Sub
Private Sub process(addloc As Single)
With mainfrm.mkt
.Close
.LocalPort = 0
End With
'Set address to be worked upon (workind is a global string in module ' 'UrlList)
UrlList.workind = addloc
'Set the remote host/port
mkt.RemoteHost = Url(addloc)
mkt.RemotePort = 80
mkt.Connect
End Sub
Private Sub mkt_Connect()
MsgBox ("")
packet = "GET / HTTP/1.1" & vbNewLine
packet = packet & "Host: " & Mid(Url(UrlList.workind), 8, Len(Url(UrlList.workind)) - 7) & vbNewLine
'Add packet terminator
packet = packet & vbNewLine
'Send data request
mkt.SendData (packet)
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
-
Jun 5th, 2006, 12:05 PM
#2
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
-
Jun 5th, 2006, 02:05 PM
#3
Thread Starter
Hyperactive Member
Re: Winsock Cryptic Error :|
 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.
-
Jun 5th, 2006, 07:39 PM
#4
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|