|
-
Jun 1st, 2006, 10:10 AM
#1
Thread Starter
New Member
Winsock Question
Hi,
I'm trying to write my first application using Winsock. I'm trying to retrieve the HTML code from a website. Here is what I have:
-------------------------------------------------
Dim WithEvents Winsock As MSWinsockLib.Winsock
Private Sub Form_Load()
With Winsock
.RemoteHost = "www.yahoo.com"
.RemotePort = 80
.Connect
.SendData "GET /"
End With
End Sub
Private Sub winsock_ondataarrival()
Dim rBuffer
rBuffer = Winsock.GetData
MsgBox rBuffer
End Sub
-------------------------------------------------
When I run it, I get:
'Run-time error '91': Object variable of With block variable not set'
When I click on 'Debug' it highlights the following line:
'.RemoteHost = "www.yahoo.com"'
Does anybody think they can point me in the right direction?
Thanks!
Tom
-
Jun 2nd, 2006, 02:28 AM
#2
PowerPoster
Re: Winsock Question
you dont need winsock for that ..
change strUrl to your own .. add a text box to display the contents .. with multiline lines and vertival scrollbars.
add a command button ...
Add Reference to MS XML version 2.0 (5.0 is the latest but certain hosts dont have it installed - I use 4.0 but same issue, so 2.0 is the safest that it is installed)
VB Code:
Private Sub Command1_Click()
Dim objHTTP As New MSXML.XMLHTTPRequest
objHTTP.Open "GET", strUrl, False
objHTTP.setRequestHeader "Content-Type", "text/html"
objHTTP.send
Text1.Text = objHTTP.responseText
End Sub
Last edited by rory; Jun 2nd, 2006 at 02:37 AM.
-
Jun 2nd, 2006, 10:26 AM
#3
Thread Starter
New Member
Re: Winsock Question
We have actually tried that and it works great. However, we figured we'd write it in Winsock to reduce some overhead. Our server will be performing this HTTP GET several times a second, so speed and resource usage are a priority.
I just assumed using MSXML.XMLHTTPRequest could not possibly be as simple and pure as a plan HTML GET by itself. Knowing Microsoft, there are 50,000 lines of code inside MSXML.XMLHTTPRequest to perform the HTTP GET.
Thoughts? Agree/disagree?
Thanks!
Tom
-
Jun 2nd, 2006, 02:24 PM
#4
Frenzied Member
Re: Winsock Question
I have an app that sends post messages to our IIS server to retrieve ASP pages and writes the html that is returned to html files back on the IIS server.
I use the Winsock API rather than the Winsock control as the final version is a batch (non-console) app that runs in the scheduler on another server and does the conversions on the first of every month, converting pages that will display the previous month's data.
Let me know if you think this will be of help and I'll email you the code. I have both the GUI version that I used to develop & test the code and the batch version.
-
Jun 2nd, 2006, 02:44 PM
#5
PowerPoster
Re: Winsock Question
I dont know Tom, never thought about it as it works so fast :-)
Though I'd like to know also ..
I use the XML get also in ASP apps especially in an indexer for a search engine, basically loops through links from a database (few hundred) and grabs the HTML .. specifically keywords, title, etc .. to display for the search.
As for VB im using the XMLHTTP to send data to an ASP page to do stuff then get the responses. Didnt think I could use winsock for that? CCoder id like to see the code if you dont mind .. i just did a patch program last night, it works fine with the way im doing it, but if I can use winsock for both the check on the AP page and also on the download of the files .. then would be better .. im using a Downloader Control built into the program.
-
Jun 2nd, 2006, 04:00 PM
#6
PowerPoster
Re: Winsock Question
ok looked around, basically this is using the winsock control ..
VB Code:
Private Sub Form_Load()
With Winsock1
.Close
.LocalPort = 0
.Connect "www.myurl.com", 80
End With
End Sub
Private Sub Winsock1_Connect()
Dim strData As String
strData = "GET / HTTP/1.1" & vbCrLf
strData = strData & "Host: www.myurl.com" & vbCrLf
strData = strData & "Connection: close" & vbCrLf
strData = strData & "Accept: */*" & vbCrLf
strData = strData & vbCrLf
Winsock1.SendData strData
Debug.Print strData
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
Dim strHeader As String
Winsock1.GetData strData
strHeader = Left$(strData, InStr(1, strData, vbCrLf & vbCrLf) - 1)
strData = Mid(strData, InStr(1, strData, vbCrLf & vbCrLf) + 4)
Debug.Print Trim$(strData)
End Sub
Last edited by rory; Jun 2nd, 2006 at 04:23 PM.
-
Jun 2nd, 2006, 06:12 PM
#7
Thread Starter
New Member
Re: Winsock Question
This code is exactly what I am 'trying' to do. My problem is, I don't know if there are any declarations (not even entirely sure what a declaration is) I need outside of this code. As explained in my first post, I get an error when trying to compile. That's actually what I can't figure out.
When I run it, I get:
'Run-time error '91': Object variable of With block variable not set'
When I click on 'Debug' it highlights the following line:
'.RemoteHost = "www.yahoo.com"'
Help?!
Tom
-
Jun 2nd, 2006, 06:36 PM
#8
PowerPoster
Re: Winsock Question
 Originally Posted by tgill3764
This code is exactly what I am 'trying' to do. My problem is, I don't know if there are any declarations (not even entirely sure what a declaration is) I need outside of this code. As explained in my first post, I get an error when trying to compile. That's actually what I can't figure out.
When I run it, I get:
'Run-time error '91': Object variable of With block variable not set'
When I click on 'Debug' it highlights the following line:
'.RemoteHost = "www.yahoo.com"'
Help?!
Tom
RemoteHost doesnt understand Names
So using your code it would connect like this . You dont send the data until it connects ...
VB Code:
Private Sub Form_Load()
With Winsock
.Connect "www.myurl.com", 80
End With
End Sub
also, why are you using this?
Dim WithEvents Winsock As MSWinsockLib.Winsock
Last edited by rory; Jun 2nd, 2006 at 06:54 PM.
-
Jun 23rd, 2006, 05:50 AM
#9
New Member
Re: Winsock Question
Does any of you guys know how to HTTP POST a local file to a web server using the MSXML component?
Further details can be seen in this thread.
http://www.vbforums.com/showthread.php?p=2520710
Sincerely,
Thomas
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
|