Re: Trying to get a web page with Winsock

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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


.



Relevant Pages

  • Re: Trying to get a web page with Winsock
    ... The code I gave you submits a simple HTTP request to a web server and displays what gets sent back and it's working fine for these URLs. ... Private sRequest As String ... Private sHTML As String ... Private Sub Winsock1_Connect ...
    (microsoft.public.vb.controls)
  • RE: Alert (message)
    ... Private Sub HotelCheckIn_LostFocus ... Dim stMsgText As String ... "Check in date is less then 14 days from the request date do you want to ...
    (microsoft.public.access.forms)
  • Re: Controlling Javascript from server side
    ... but five different language implementations here. ... 'true' means that the request must be handled asynchronously. ... There is exactly *no* reason for such a thing here. ... | percent-endoded string). ...
    (comp.lang.javascript)
  • Re: Is it ok to change $ENV{QUERY_STRING} before "use CGI;" is called..?
    ... the big advantage of wiki, ... It does url-encode if its option is set to use UTF-8 request, ... string for GET requests. ... because "query string" in URL is anyway just a string ...
    (comp.lang.perl.misc)
  • Re: Problems installing Microsoft .NET Framework 1.1 Service Pack
    ... and it worked and I have filled in the request and sent it. ... An unhandled exception occurred during the execution of the ... siteName, String httpVerb, String path, String QS, String httpVersion, ... request, String site, TicketState& ticketState, String& responseHeaders) +100 ...
    (microsoft.public.windowsupdate)