Results 1 to 9 of 9

Thread: xmlhttp async problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    143

    xmlhttp async problem

    i am trying to make xmlhttp async and make some kind of state changed event but my code failed

    Sub HandleStateChange()

    If (myMSXML.readyState = 4) Then
    MsgBox myMSXML.responseText
    End If
    End Sub

    please help
    Last edited by geekmaro; Oct 25th, 2020 at 01:40 AM.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    21,660

    Re: xmlhttp async problem

    A problem with MSXML is that the bonehead parts of it were optimized for use from JScript. As a result you have to simulate JScript event binding in VB6.

    Form1.frm
    Code:
    Option Explicit
    
    Private HTTP As MSXML2.XMLHTTP60
    Private WithEvents SinkRSChange As SinkRSChange
    
    Private Sub Form_Load()
        Set HTTP = New MSXML2.XMLHTTP60
        Set SinkRSChange = New SinkRSChange
    End Sub
    
    Private Sub Form_Resize()
        If WindowState <> vbMinimized Then
            Text1.Move 0, 0, ScaleWidth, ScaleHeight
        End If
    End Sub
    
    Private Sub mnuGo_Click()
        With HTTP
            .open "GET", "https://www.google.com/", True
            .onreadystatechange = SinkRSChange
            Text1.Text = "Starting async GET" & vbNewLine
            .send
        End With
    End Sub
    
    Private Sub SinkRSChange_onreadystatechange()
        With HTTP
            Text1.Text = Text1.Text & vbNewLine & "readyState = " & CStr(.readyState)
            If .readyState = 4 Then
                Text1.Text = Text1.Text _
                           & vbNewLine & vbNewLine _
                           & CStr(.Status) & " " & .statusText _
                           & vbNewLine & vbNewLine _
                           & .responseText
            End If
        End With
    End Sub
    SinkRSChange.cls
    Code:
    Option Explicit
    
    Public Event onreadystatechange()
    
    'Mark as default member via Tools|Procedure Attributes... dialog.
    Public Sub RSChange()
        RaiseEvent onreadystatechange
    End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    143

    Re: xmlhttp async problem

    Quote Originally Posted by dilettante View Post
    A problem with MSXML is that the bonehead parts of it were optimized for use from JScript. As a result you have to simulate JScript event binding in VB6.

    Form1.frm
    Code:
    Option Explicit
    
    Private HTTP As MSXML2.XMLHTTP60
    Private WithEvents SinkRSChange As SinkRSChange
    
    Private Sub Form_Load()
        Set HTTP = New MSXML2.XMLHTTP60
        Set SinkRSChange = New SinkRSChange
    End Sub
    
    Private Sub Form_Resize()
        If WindowState <> vbMinimized Then
            Text1.Move 0, 0, ScaleWidth, ScaleHeight
        End If
    End Sub
    
    Private Sub mnuGo_Click()
        With HTTP
            .open "GET", "https://www.google.com/", True
            .onreadystatechange = SinkRSChange
            Text1.Text = "Starting async GET" & vbNewLine
            .send
        End With
    End Sub
    
    Private Sub SinkRSChange_onreadystatechange()
        With HTTP
            Text1.Text = Text1.Text & vbNewLine & "readyState = " & CStr(.readyState)
            If .readyState = 4 Then
                Text1.Text = Text1.Text _
                           & vbNewLine & vbNewLine _
                           & CStr(.Status) & " " & .statusText _
                           & vbNewLine & vbNewLine _
                           & .responseText
            End If
        End With
    End Sub
    SinkRSChange.cls
    Code:
    Option Explicit
    
    Public Event onreadystatechange()
    
    'Mark as default member via Tools|Procedure Attributes... dialog.
    Public Sub RSChange()
        RaiseEvent onreadystatechange
    End Sub
    could you please send me the whole project in archive like zip
    because i tried your code and code error at line; WithEvents SinkRSChange As SinkRSChange, it shows user defined type not defined
    and also the procedure attribute part i dont know how to do it
    thanks alot

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    21,660

    Re: xmlhttp async problem

    I'm not sure that will help because you will have to set or verify the attribute in your own programs. Small edits can easily wipe it out.

    Did you create a class named SinkRSChange?
    Attached Files Attached Files

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    143

    Re: xmlhttp async problem

    Quote Originally Posted by dilettante View Post
    I'm not sure that will help because you will have to set or verify the attribute in your own programs. Small edits can easily wipe it out.

    Did you create a class named SinkRSChange?
    it works but i have just one problem with posting cookies:
    i tried this but didnt work

    .setRequestHeader "Cookie", "PHPSESSID=ane07viahn98n5xjagv777xx82; session=7723030430c4c6c52896479492e2e546e52189c6235412e4e3372737a4c382f542d4a6569614b7a7a774653667a4 c68694a766852456b685a2e6771586a634a7a7946486174382f2f455733754867714a6644425530"

    please help
    Last edited by geekmaro; Oct 25th, 2020 at 06:31 PM.

  6. #6
    Hyperactive Member
    Join Date
    Jan 2020
    Posts
    466

    Re: xmlhttp async problem

    you can use winhttprequest 5.1,so you you can remove xmlhttp object

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    143

    Re: xmlhttp async problem

    Quote Originally Posted by xiaoyao View Post
    you can use winhttprequest 5.1,so you you can remove xmlhttp object
    with winhttp i cant post cookies, my goal is to make a post request using cookies
    only with xmlhttp i was able to obtain cookies, now i just need to post them
    please help me
    thank you

  8. #8
    Hyperactive Member
    Join Date
    Jan 2020
    Posts
    466

    Re: xmlhttp async problem

    winhttp can use cookie

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    143

    Re: xmlhttp async problem

    Quote Originally Posted by xiaoyao View Post
    winhttp can use cookie
    i cant get cookies with it, i could only get first part of cookies, but not session id, and session is part of cookies

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width