Jump to content

Recommended Posts

Posted

Hi everyone,

Sorry for my bad English.

I have a question: How to Clone the WinHttp Object.

To make it easier to imagine, I have a piece of code like this:

Local $oHTTP = ObjCreate('winhttp.winhttprequest.5.1')
#Region LOGIN
    $oHTTP.Open("GET", 'https://www.autoitscript.com/forum/login/', True)
    $oHTTP.Send()
    $oHTTP.WaitForResponse()
    $csrfKey = StringRegExp($oHTTP.ResponseText, 'name="csrfKey" value="(.*?)"', 1)[0]
    $oHTTP.Open("POST", 'https://www.autoitscript.com/forum/login/', True)
    $oHTTP.SetRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
    $oHTTP.Send('csrfKey=' & $csrfKey & '&ref=&auth=newbie321&password=123456&remember_me=1&_processLogin=usernamepassword&_processLogin=usernamepassword')
    $oHTTP.WaitForResponse()
#EndRegion

$oHTTP1 = $oHTTP ; <= replace this line with CloneWinHttpObj
$oHTTP2 = $oHTTP ; <= replace this line with CloneWinHttpObj

$oHTTP1.Open("GET", 'https://www.autoitscript.com/forum/forum/2-autoit-general-help-and-support/', True)
$oHTTP1.Send()

$oHTTP2.Open("GET", 'https://www.autoitscript.com/forum/forum/10-autoit-gui-help-and-support/', True)
$oHTTP2.Send()

$oHTTP1.WaitForResponse()
$oHTTP2.WaitForResponse()

MsgBox(0, 'Compare', $oHTTP1.ResponseText = $oHTTP2.ResponseText)

Func CloneWinHttpObj($sourceObj, $destObj)
    ;??????????????????????????????
EndFunc

The result of the code is True because $oHTTP1 and $oHTTP2 are the same source.

How to clone $oHTTP into $oHTTP1 and $oHTTP2 so that they will bear the same characteristics of $oHTTP (Cookies). That will help me don't need to login twice.

Thanks for your help ^^ 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...