Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

vb control to request a URL.  Winsock or another lightweight method to carry http request

Posted on 2003-10-29
7
Medium Priority
?
407 Views
Last Modified: 2013-12-25
I would like to know if anyone has a suggestion for a very simple VB app to simply request a web page.  The request in it of itself triggers the more useful features.  I've tried using the Microsoft Winsock control but this one works with other controls of its kind.  I tried using this control for connecting to a server and requesting the page but this did not work.  The Internet Transfer Control seems to be a bit too big for such a simple request.  
Any suggestions.
0
Comment
Question by:bisonfur37
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 80 total points
ID: 9645618
Is the WebBrowser control too big for your liking?
0
 
LVL 2

Author Comment

by:bisonfur37
ID: 9647534
I believe the WebBrowser control is only a megabyte.  Is this the smallest control for simple http requests?  Would anything smaller turn this solution into something complex/cumbersome.  Thank you for your response.
0
 
LVL 5

Assisted Solution

by:fantasy1001
fantasy1001 earned 200 total points
ID: 9647689
Try this
Private Sub Command1_Click()
Dim IE
Set IE = CreateObject("InternetExplorer.Application")
  IE.Navigate "http://www.google.com"
  IE.Visible = True
 
  While IE.Busy
      DoEvents
  Wend
End Sub

Thanks
Fantasy
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Assisted Solution

by:AbuMariam
AbuMariam earned 120 total points
ID: 9648590
If I understand your request, try this:

Call Shell("C:\Program Files\Internet Explorer\IEXPLORE.EXE www.google.com", vbMaximizedFocus)

0
 
LVL 9

Assisted Solution

by:Dang123
Dang123 earned 160 total points
ID: 9649812
A great site to look at for this would be

http://www.vbip.com/

To start off, here is a set of tutorials on the site that use winsock to download web pages

HTTP with MS Winsock Control - Part I - How to download a file from the Web
http://www.vbip.com/winsock/winsock_http_01.asp

HTTP with MS Winsock Control - Part II - How to track the progress of data transfer
http://www.vbip.com/winsock/winsock_http_02_01.asp

The set goes to 7 tutorials, but these look like they should answer you question (you can find all of them listed on the main page)
0
 
LVL 1

Accepted Solution

by:
Yrag1 earned 240 total points
ID: 9652928
Copy and paste this into a standard vb exe
it uses the windows api's to connect to a website and receives all the data for a specified page.
the combo box will store url's for you


Const scUserAgent = "Test prog" 'this is logged as the agent name on the webserver
Const myURL = "http://www.kenhall.org.uk" 'my website
Const INTERNET_OPEN_TYPE_DIRECT = 1
Const INTERNET_OPEN_TYPE_PROXY = 3
Const INTERNET_FLAG_RELOAD = &H80000000
Private Declare Function InternetOpen Lib "wininet" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetCloseHandle Lib "wininet" (ByVal hInet As Long) As Integer
Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetOpenUrl Lib "wininet" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long

Public Sub getHTML()
    sURL = Combo1.Text
    Dim hOpen As Long, hFile As Long, sBuffer As String, Ret As Long
    'Create a buffer for the file we're going to download
    sBuffer = Space(2000000)
    'Create an internet connection
    hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
    'Open the url
    hFile = InternetOpenUrl(hOpen, sURL, vbNullString, ByVal 0&, INTERNET_FLAG_RELOAD, ByVal 0&)
    'Read the first 1000 bytes of the file
    InternetReadFile hFile, sBuffer, 1000, Ret
    'MsgBox Ret
    'clean up
    InternetCloseHandle hFile
    InternetCloseHandle hOpen
    'Show our file
    If InStr(1, sBuffer, "<html>") = 0 Then
        RichTextBox1.Text = "Your URL was incorrect"
    Else
        RichTextBox1.Text = sBuffer
    End If
End Sub

Private Sub Command1_Click()

       Combo1.AddItem (Combo1.Text)
       getHTML
End Sub

Private Sub Form_Load()
    Combo1.AddItem (myURL)
    Command1.Caption = "Get Page"
End Sub


Hope this works for you
Gary
0
 
LVL 5

Expert Comment

by:fantasy1001
ID: 9683260
Just for your information:

Create a new form with a textbox (multiline set to true), a command button. Add a component named Microsoft HTML Object Library

sub Command1_OnClick
    Dim objMSHTML As New HTMLDocument
    Dim objDoc As HTMLDocument
    Set objDoc = objMSHTML.createDocumentFromUrl("http://www.intel.com", vbNullString)
   
    While objDoc.readyState <> "complete"
        DoEvents
    Wend
    Text1.Text = objDoc.documentElement.innerHTML   'set to innertext if you want only text
end sub

~ fantasy ~
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question