Re: Trying to get a web page with Winsock
- From: Lamont <Lamont@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 29 Dec 2007 01:55:00 -0800
Hello Bob and Jeff,
Thank you for kind assistance. Using the fix code Bob gave me,
I succeeded in getting a page from Yahoo which said
"Sorry, the page you requested was not found."
and suggested
"You may also want to try <a
href="http://yp.yahoo.com/Index.htm"><b>http://yp.yahoo.com/Index.htm</b></a>"
but "http://yp.yahoo.com/Index.htm" was what I had in my request already.
In the course of trying all kinds of variations in the request line, I lost
track of the code
that had gotten the response from Yahoo, and could not reproduce this result.
I thought, Due Diligence says "When all else fails, Read the Instructions"
and I read RFC 2616.
Tried and failed with many variations of constructing the HTTP GET request.
so finally I just
assigned the sample line out of RFC2616 to the request string.
sRequest = "GET http://www.w3.org/pub/WWW/TheProject.html HTTP/1.1" & vbCrLf
& vbCrLf
This fails with "40006 Wrong protocol or connection state for the requested
transaction or request"
So, my error is not in this request string, but in lack of understanding of
how to use the
Winsock to send a connection request.
Here is the code that fails with
"40006 Wrong protocol or connection state for the requested transaction or
request"
Winsock1_Connect and Winsock1_ConnectionRequest and Winsock1_DataArrival do
not fire, of course.
Option Explicit
Private sRequest As String
Private sHTML As String
Private Sub cmdConnect_Click()
Winsock1.RemoteHost = "http://yp.yahoo.com"
Winsock1.RemotePort = 80
sRequest = "GET http://www.w3.org/pub/WWW/TheProject.html HTTP/1.1" &
vbCrLf & vbCrLf
Call Winsock1.Connect
sHTML = ""
On Error GoTo cmdErr
Winsock1.SendData sRequest
Winsock1.Close
End
cmdErr:
Debug.Print Err.Number & " "; Err.Description
Winsock1.Close
End
End Sub
Private Sub Winsock1_Connect()
Debug.Print "Winsock1_Connect()"
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Debug.Print "Winsock1_ConnectionRequest"
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim sTemp As String
Winsock1.GetData sTemp
Debug.Print "sTemp=" & sTemp
sHTML = sHTML & sTemp
End Sub
Private Sub Winsock1_Error(ByVal Number As Integer, Description As String,
ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal
HelpContext As Long, CancelDisplay As Boolean)
'Winsock1.Close
MsgBox Description, vbOKOnly, "Error"
End Sub
About: The winsock works fine although IIRC it's more complicated
I don't know what IIRC is. I'm 169 years old and I huff and puff, trying
to catch
up with the modern world. (Well, maybe I exaggerate 100 years, but that's
what it seems like.)
You gentlemen who devote so much time to helping others who are struggling
are Good
Samaritans or Saints or Knights in Shinning Armor, or ... some such.
--
Lamont Phemister
"Bob Butler" wrote:
"Jeff Johnson" <i.get@xxxxxxxxxxx> wrote in message.
news:13naoefd8lu532a@xxxxxxxxxxxxxxxxxxxxx
"Bob Butler" <noway@xxxxxxxxxxx> wrote in message
news:OisnsUWSIHA.4880@xxxxxxxxxxxxxxxxxxxxxxx
This may get you closer; you'll still have to determine the hostname,
port and request info for the page you want:
I say skip Winsock altogether and go with the WinHttpRequest object
(WINHTTP.dll, although this may be deprecated) or the XmlHttp object
(MSXML3.dll in my case).
The winsock works fine although IIRC it's more complicated if a proxy is
needed. I usually use the HttpSendRequest API call...
http://groups.google.com/group/microsoft.public.vb.general.discussion/browse_thread/thread/258cad32b77c0030/8181a87bf1664f50?lnk=st&q=submithtmlform#8181a87bf1664f50
- Follow-Ups:
- Re: Trying to get a web page with Winsock
- From: Bob Butler
- Re: Trying to get a web page with Winsock
- References:
- Re: Trying to get a web page with Winsock
- From: Bob Butler
- Re: Trying to get a web page with Winsock
- From: Jeff Johnson
- Re: Trying to get a web page with Winsock
- From: Bob Butler
- Re: Trying to get a web page with Winsock
- Prev by Date: Re: Trying to get a web page with Winsock
- Next by Date: Re: Trying to get a web page with Winsock
- Previous by thread: Re: Trying to get a web page with Winsock
- Next by thread: Re: Trying to get a web page with Winsock
- Index(es):
Relevant Pages
|