Solved

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

Posted on 2003-10-29
7
377 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
7 Comments
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 20 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 50 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Assisted Solution

by:AbuMariam
AbuMariam earned 30 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 40 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 60 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now