locked
How to make connection to the server non-persistence using wininet? RRS feed

  • Question

  • Hi,

    I am using wininet InternetOpen url method to get the user info from our server and immediately closing the internet handle. Please see my attached code. I have been running into number of connections to the server issue mentioned at http://support.microsoft.com/default.aspx?scid=kb;EN-US;q183110 .

    [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
    MaxConnectionsPerServer = 2 (default value)
    MaxConnectionsPer1_0Server = 4 (default value)

    After I made MaxConnectionsPerServer invocation, the next invocation is getting stuck. Though http://support.microsoft.com/kb/813827 mentioned keep alive timer default value is 1 minute, I noticed that my new invocation doesn't start working after hour also.

    The article http://support.microsoft.com/kb/259984 mentioned about non-persistent state but it is for HTTP 1.1 server only. I am not aware of HTTP 1.0 0r 1.1 concepts. I just want to make sure that all my connection to the given server(in my code sever name is userdb.ky) should be non-persistent so that there should not be any MaxConnectionsPerServer limit.

    Could you please help me to get this task done.

    Sub GetUserInformation()
        On Error GoTo Err_handler:
        Dim hOpen As Long
        Dim hConn As Long
        Dim sUrl As String
        Dim userId As Long
        userId = 12345
     
        sUrl = "https://userdb.ky:14401/userinfo.cgi?q=" & userId
     
        ' create an internet connection, open link and do clean up
        hOpen = InternetOpen("GetUserInformation", INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
           
        hConn = InternetOpenUrl(hOpen, sUrl, vbNullString, ByVal 0&, INTERNET_FLAG_RELOAD, ByVal 0&)
        
        InternetCloseHandle hConn
        InternetCloseHandle hOpen
     
        Exit Sub
    Err_handler:
        MsgBox "Error in opening internet URL.", vbOKOnly, "GetUserInfo"
        
    End Sub


    Thanks, Megha
    Monday, September 28, 2009 10:34 AM

Answers

  • I couldn't get how to make connection non-persistent or how to solve the maxconnectionsperserver limit issue but I got below code working.

       sUrl = "https://userdb.ky:14401/getuserinfo.cgi" ###Replace this with your link###
            
        Dim strPostData As String
        Dim objRequest As Object

        strPostData = "q=12345"  ##You can specify the expected input for specified URL here####
        Set objRequest = New MSXML2.XMLHTTP
        With objRequest
            .Open "POST", sUrl, False
            .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
            .Send (strPostData)
            GetSessionId = .responseText
        End With
        
        If objRequest.Status <> 200 Then
           MsgBox "Error occured: " & objReques.Status
           GoTo OnExit
        End If
        
        Set objRequest = Nothing

    OnExit:
        Set objRequest = Nothing

    Thanks.
    • Marked as answer by CSharpLeader Tuesday, September 29, 2009 5:33 AM
    Tuesday, September 29, 2009 5:33 AM