Microsoft KB Archive/171271: Difference between revisions

From BetaArchive Wiki
m (Text replacement - ">" to ">")
m (Text replacement - """ to """)
Line 12: Line 12:
<div id="TitleRow">
<div id="TitleRow">


= <span id="KB171271"></span>FIX: Internet Transfer Control 5.0 Has Bug with &quot;HEAD&quot; Request =
= <span id="KB171271"></span>FIX: Internet Transfer Control 5.0 Has Bug with "HEAD" Request =




Line 45: Line 45:
== SYMPTOMS ==
== SYMPTOMS ==


The Internet Transfer Control 5.0 &quot;HEAD&quot; request does not work based on the documentation provided by Microsoft. There is no header information being returned when the Execute method and &quot;HEAD&quot; request are sent to the web server.
The Internet Transfer Control 5.0 "HEAD" request does not work based on the documentation provided by Microsoft. There is no header information being returned when the Execute method and "HEAD" request are sent to the web server.


</div>
</div>
Line 52: Line 52:
== RESOLUTION ==
== RESOLUTION ==


The Internet Transfer Control 5.0 &quot;HEAD&quot; request does not work from Visual Basic 5.0. You need to use the WinInet APIs that are included with the ActiveX SDK to get header information from your server. Specifically the InternetOpen, InternetConnect, HttpOpenRequest, HttpSendRequest, and HttpQueryInfo are the WinInet APIs you need to use. In the sample code below, get the header information from:<br />
The Internet Transfer Control 5.0 "HEAD" request does not work from Visual Basic 5.0. You need to use the WinInet APIs that are included with the ActiveX SDK to get header information from your server. Specifically the InternetOpen, InternetConnect, HttpOpenRequest, HttpSendRequest, and HttpQueryInfo are the WinInet APIs you need to use. In the sample code below, get the header information from:<br />


<div class="indent">
<div class="indent">
Line 66: Line 66:
<li>Run Visual Basic or, if Visual Basic is already running, choose New Project from the File menu (ALT, F, N). Form1 is created by default.</li>
<li>Run Visual Basic or, if Visual Basic is already running, choose New Project from the File menu (ALT, F, N). Form1 is created by default.</li>
<li><p>Add the following code to the general declarations section of Form1:</p>
<li><p>Add the following code to the general declarations section of Form1:</p>
<pre class="codesample">      Private Declare Function InternetOpen Lib &quot;wininet.dll&quot; _
<pre class="codesample">      Private Declare Function InternetOpen Lib "wininet.dll" _
                                           Alias &quot;InternetOpenA&quot; _
                                           Alias "InternetOpenA" _
                   (ByVal lpszCallerName As String, _
                   (ByVal lpszCallerName As String, _
                   ByVal dwAccessType As Long, _
                   ByVal dwAccessType As Long, _
Line 74: Line 74:
                   ByVal dwFlags As Long) As Long
                   ByVal dwFlags As Long) As Long


       Private Declare Function InternetConnect Lib &quot;wininet.dll&quot; _
       Private Declare Function InternetConnect Lib "wininet.dll" _
                                           Alias &quot;InternetConnectA&quot; _
                                           Alias "InternetConnectA" _
                   (ByVal hInternetSession As Long, _
                   (ByVal hInternetSession As Long, _
                   ByVal lpszServerName As String, _
                   ByVal lpszServerName As String, _
Line 85: Line 85:
                   ByVal dwContext As Long) As Long
                   ByVal dwContext As Long) As Long


       Private Declare Function HttpOpenRequest Lib &quot;wininet.dll&quot; _
       Private Declare Function HttpOpenRequest Lib "wininet.dll" _
                                             Alias &quot;HttpOpenRequestA&quot; _
                                             Alias "HttpOpenRequestA" _
                   (ByVal hInternetSession As Long, _
                   (ByVal hInternetSession As Long, _
                   ByVal lpszVerb As String, _
                   ByVal lpszVerb As String, _
Line 96: Line 96:
                   ByVal dwContext As Long) As Long
                   ByVal dwContext As Long) As Long


       Private Declare Function HttpSendRequest Lib &quot;wininet.dll&quot; _
       Private Declare Function HttpSendRequest Lib "wininet.dll" _
                                             Alias &quot;HttpSendRequestA&quot; _
                                             Alias "HttpSendRequestA" _
                   (ByVal hHttpRequest As Long, _
                   (ByVal hHttpRequest As Long, _
                   ByVal sHeaders As String, _
                   ByVal sHeaders As String, _
Line 104: Line 104:
                   ByVal lOptionalLength As Long) As Boolean
                   ByVal lOptionalLength As Long) As Boolean


       Private Declare Function HttpQueryInfo Lib &quot;wininet.dll&quot; _
       Private Declare Function HttpQueryInfo Lib "wininet.dll" _
                                                 Alias &quot;HttpQueryInfoA&quot; _
                                                 Alias "HttpQueryInfoA" _
                   (ByVal hHttpRequest As Long, _
                   (ByVal hHttpRequest As Long, _
                   ByVal lInfoLevel As Long, _
                   ByVal lInfoLevel As Long, _
Line 112: Line 112:
                   ByRef lIndex As Long) As Boolean
                   ByRef lIndex As Long) As Boolean


       Private Declare Function InternetCloseHandle Lib &quot;wininet.dll&quot; _
       Private Declare Function InternetCloseHandle Lib "wininet.dll" _
                   (ByVal hInternetHandle As Long) As Boolean
                   (ByVal hInternetHandle As Long) As Boolean


Line 134: Line 134:
         Const INTERNET_OPEN_TYPE_PRECONFIG = 0
         Const INTERNET_OPEN_TYPE_PRECONFIG = 0


         hInternetOpen = InternetOpen(&quot;http generic&quot;, _
         hInternetOpen = InternetOpen("http generic", _
                               INTERNET_OPEN_TYPE_PRECONFIG, _
                               INTERNET_OPEN_TYPE_PRECONFIG, _
                               vbNullString, _
                               vbNullString, _
Line 146: Line 146:


             hInternetConnect = InternetConnect(hInternetOpen, _
             hInternetConnect = InternetConnect(hInternetOpen, _
                               &quot;www.microsoft.com&quot;, _
                               "www.microsoft.com", _
                               INTERNET_DEFAULT_HTTP_PORT, _
                               INTERNET_DEFAULT_HTTP_PORT, _
                               vbNullString, _  
                               vbNullString, _  
                               &quot;HTTP/1.0&quot;, _  
                               "HTTP/1.0", _  
                               INTERNET_SERVICE_HTTP, _  
                               INTERNET_SERVICE_HTTP, _  
                               0, _
                               0, _
Line 158: Line 158:


           hHttpOpenRequest = HttpOpenRequest(hInternetConnect, _  
           hHttpOpenRequest = HttpOpenRequest(hInternetConnect, _  
                               &quot;HEAD&quot;, _  
                               "HEAD", _  
                               &quot;default.htm&quot;, _  
                               "default.htm", _  
                               vbNullString, _  
                               vbNullString, _  
                               vbNullString, _  
                               vbNullString, _  
Line 208: Line 208:
                         = 1) Then
                         = 1) Then
                         List1.AddItem sBuff
                         List1.AddItem sBuff
                       End If&quot;?> Dim sBuff As String * 1024  
                       End If"?> Dim sBuff As String * 1024  
Dim lBuffLen As Long  
Dim lBuffLen As Long  
lBuffLen = Len(sBuff)  
lBuffLen = Len(sBuff)  
Line 295: Line 295:
<pre class="codesample">      Private Sub Command1_Click()
<pre class="codesample">      Private Sub Command1_Click()
         Dim strURL As String
         Dim strURL As String
         strURL = &quot;http://www.microsoft.com&quot;
         strURL = "http://www.microsoft.com"
         Inet2.Execute URL:=strURL, Operation:=&quot;HEAD&quot;
         Inet2.Execute URL:=strURL, Operation:="HEAD"
       End Sub
       End Sub



Revision as of 10:05, 21 July 2020

Article ID: 171271

Article Last Modified on 8/20/2007



APPLIES TO

  • Microsoft Visual Basic 5.0 Control Creation Edition
  • Microsoft Visual Basic 5.0 Professional Edition



This article was previously published under Q171271

SYMPTOMS

The Internet Transfer Control 5.0 "HEAD" request does not work based on the documentation provided by Microsoft. There is no header information being returned when the Execute method and "HEAD" request are sent to the web server.

RESOLUTION

The Internet Transfer Control 5.0 "HEAD" request does not work from Visual Basic 5.0. You need to use the WinInet APIs that are included with the ActiveX SDK to get header information from your server. Specifically the InternetOpen, InternetConnect, HttpOpenRequest, HttpSendRequest, and HttpQueryInfo are the WinInet APIs you need to use. In the sample code below, get the header information from:


The following code can be used to work around this problem:

  1. Run Visual Basic or, if Visual Basic is already running, choose New Project from the File menu (ALT, F, N). Form1 is created by default.
  2. Add the following code to the general declarations section of Form1:

          Private Declare Function InternetOpen Lib "wininet.dll" _
                                               Alias "InternetOpenA" _
                      (ByVal lpszCallerName As String, _
                      ByVal dwAccessType As Long, _
                      ByVal lpszProxyName As String, _
                      ByVal lpszProxyBypass As String, _
                      ByVal dwFlags As Long) As Long
    
          Private Declare Function InternetConnect Lib "wininet.dll" _
                                              Alias "InternetConnectA" _
                      (ByVal hInternetSession As Long, _
                      ByVal lpszServerName As String, _
                      ByVal nProxyPort As Integer, _
                      ByVal lpszUsername As String, _
                      ByVal lpszPassword As String, _
                      ByVal dwService As Long, _
                      ByVal dwFlags As Long, _
                      ByVal dwContext As Long) As Long
    
          Private Declare Function HttpOpenRequest Lib "wininet.dll" _
                                                Alias "HttpOpenRequestA" _
                      (ByVal hInternetSession As Long, _
                      ByVal lpszVerb As String, _
                      ByVal lpszObjectName As String, _
                      ByVal lpszVersion As String, _
                      ByVal lpszReferer As String, _
                      ByVal lpszAcceptTypes As Long, _
                      ByVal dwFlags As Long, _
                      ByVal dwContext As Long) As Long
    
          Private Declare Function HttpSendRequest Lib "wininet.dll" _
                                                Alias "HttpSendRequestA" _
                      (ByVal hHttpRequest As Long, _
                      ByVal sHeaders As String, _
                      ByVal lHeadersLength As Long, _
                      ByVal sOptional As String, _
                      ByVal lOptionalLength As Long) As Boolean
    
          Private Declare Function HttpQueryInfo Lib "wininet.dll" _
                                                     Alias "HttpQueryInfoA" _
                      (ByVal hHttpRequest As Long, _
                      ByVal lInfoLevel As Long, _
                      ByVal sBuffer As Any, _
                      ByRef lBufferLength As Long, _
                      ByRef lIndex As Long) As Boolean
    
          Private Declare Function InternetCloseHandle Lib "wininet.dll" _
                       (ByVal hInternetHandle As Long) As Boolean
    
                            
  3. From the Project menu, choose Components, and select the Internet Transfer Control 5.0 into the project if it is not already loaded.
  4. Place a Internet Transfer Control 5.0(Inet1) on Form1.
  5. Place a ListBox Control(List1) on Form1.
  6. Place a CommandButton (Command1) on Form1 and add the following code.

          Private Sub Command1_Click()
    
                Dim hInternetOpen As Long
                Dim hInternetConnect As Long
                Dim hHttpOpenRequest As Long
                Dim bRet As Boolean
    
                hInternetOpen = 0
                hInternetConnect = 0
                hHttpOpenRequest = 0
    
             ' Use registry access settings.
             Const INTERNET_OPEN_TYPE_PRECONFIG = 0
    
             hInternetOpen = InternetOpen("http generic", _
                                   INTERNET_OPEN_TYPE_PRECONFIG, _
                                   vbNullString, _
                                   vbNullString, _
                                   0)
    
             If hInternetOpen <> 0 Then
                ' Type of service to access.
                Const INTERNET_SERVICE_HTTP = 3
                Const INTERNET_DEFAULT_HTTP_PORT = 80
    
                hInternetConnect = InternetConnect(hInternetOpen, _
                                   "www.microsoft.com", _
                                   INTERNET_DEFAULT_HTTP_PORT, _
                                   vbNullString, _ 
                                   "HTTP/1.0", _ 
                                   INTERNET_SERVICE_HTTP, _ 
                                   0, _
                                   0)
               If hInternetConnect <> 0 Then
                ' Brings the data across the wire even if it locally cached.
                Const INTERNET_FLAG_RELOAD = &H80000000
    
               hHttpOpenRequest = HttpOpenRequest(hInternetConnect, _ 
                                  "HEAD", _ 
                                  "default.htm", _ 
                                  vbNullString, _ 
                                  vbNullString, _ 
                                  0, _
                                  INTERNET_FLAG_RELOAD, _ 
                                  0)
    
                 If hHttpOpenRequest <> 0 Then
    
    
                   bRet = HttpSendRequest(hHttpOpenRequest, _
                                   vbNullString, _
                                   0, _
                                   vbNullString, _
                                   0)
    
                ' Headers to query
                 Const HTTP_QUERY_CONTENT_TYPE = 1
                 Const HTTP_QUERY_VERSION = 18
                 Const HTTP_QUERY_SERVER = 37
                 Const HTTP_QUERY_REQUEST_METHOD = 45
    
                   If bRet Then
                       Dim sBuff  As String * 1024
                       Dim lBuffLen   As Long
                          lBuffLen = Len(sBuff)
                       &apos;response headers
                          If (HttpQueryInfo(hHttpOpenRequest, _
                              HTTP_QUERY_CONTENT_TYPE, sBuff, lBuffLen, 0) _
                            = 1) Then
                            List1.AddItem sBuff
                          End If
    
                          If (HttpQueryInfo(hHttpOpenRequest, _
                                   HTTP_QUERY_VERSION, sBuff, lBuffLen, 0) _
                            = 1) Then
                            List1.AddItem sBuff
                          End If
    
                          If (HttpQueryInfo(hHttpOpenRequest, _
                                    HTTP_QUERY_SERVER, sBuff, lBuffLen, 0) _
                            = 1) Then
                            List1.AddItem sBuff
                          End If
    
                          If (HttpQueryInfo(hHttpOpenRequest, _
                            HTTP_QUERY_REQUEST_METHOD, sBuff, lBuffLen, 0) _
                            = 1) Then
                            List1.AddItem sBuff
                          End If"?> Dim sBuff As String * 1024 
    Dim lBuffLen As Long 
    lBuffLen = Len(sBuff) 
    'response headers 
    If (HttpQueryInfo(hHttpOpenRequest, _ HTTP_QUERY_CONTENT_TYPE, sBuff, lBuffLen, 0) _ = 1) Then 
        List1.AddItem sBuff 
    End If
    
    lBuffLen = Len(sBuff) 
    If (HttpQueryInfo(hHttpOpenRequest, _ HTTP_QUERY_VERSION, sBuff, lBuffLen, 0) _ = 1) Then 
        List1.AddItem sBuff 
    End If 
    
    lBuffLen = Len(sBuff) 
    If (HttpQueryInfo(hHttpOpenRequest, _ HTTP_QUERY_SERVER, sBuff, lBuffLen, 0) _ = 1) Then 
        List1.AddItem sBuff 
    End If 
    
    lBuffLen = Len(sBuff) 
    If (HttpQueryInfo(hHttpOpenRequest, _ HTTP_QUERY_REQUEST_METHOD, sBuff, lBuffLen, 0) _ = 1) Then 
        List1.AddItem sBuff 
    End If 
    
                   End If
                 End If
               End If
             End If
    
             ' Close all handles
             If hInternetOpen <> 0 Then
               bRet = InternetCloseHandle(hInternetOpen)
             End If
    
             If hInternetConnect <> 0 Then
               bRet = InternetCloseHandle(hInternetConnect)
             End If
    
             If hHttpOpenRequest <> 0 Then
               bRet = InternetCloseHandle(hHttpOpenRequest)
             End If
    
          End Sub
    
                            
  7. From the Run menu, choose Start (ALT, R, S), or press the F5 key to run the program. Press the Command1 button and garbage will be posted to your server.


STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug has been fixed in Visual Studio 97 Service Pack 2.

For more information on the Visual Studio 97 Service Pack 2, please see the following article in the Microsoft Knowledge Base:

170365 : INFO: Visual Studio 97 Service Packs - What, Where, and Why



For a list of the Visual Basic 5.0 bugs that were fixed in the Visual Studio 97 Service Pack 2, please see the following article in the Microsoft Knowledge Base:

171554 : INFO: Visual Basic 5.0 Fixes in Visual Studio 97 Service Pack 2


MORE INFORMATION

Steps to Reproduce Behavior

  1. Run Visual Basic, or if Visual Basic is already running, choose New Project from the File menu (ALT, F, N). Form1 is created by default.
  2. From the Project menu, choose Components, and select the Internet Transfer Control 5.0 into the project if it is not already loaded.
  3. Place a Internet Transfer Control 5.0(Inet1) on Form1.
  4. Place a ListBox Control(List1) on Form1.
  5. Place a CommandButton (Command1) on Form1 and add the following code.

          Private Sub Command1_Click()
            Dim strURL As String
            strURL = "http://www.microsoft.com"
            Inet2.Execute URL:=strURL, Operation:="HEAD"
          End Sub
    
                            
  6. From the Run menu, choose Start (ALT, R, S) or press the F5 key to run the program. Press the Command1 button and garbage will be posted to your server.


REFERENCES

ActiveX SDK

Keywords: kbbug kbfix kbvbp500sp2fix kbvs97sp2fix KB171271