Jump to content

Recommended Posts

Posted
Global $LastPage = InputBox("Page 1 to x", "Enter last page", "5")

Test()

Func Test()

For $i = 1 to $LastPage
    ConsoleWrite($i & @CRLF)
   Sleep(500)
Next
EndFunc

I am having an issue with an API being called x amount of times when used in a function. The code above is working but not when I use the API below , it returns the same "page 1" twice.

 I am getting the correct return URL from $Page each time it runs. 

"status":{"code":200,"text":"OK"},"meta":{"page":1,"limit":100,"total":100}

"status":{"code":200,"text":"OK"},"meta":{"page":1,"limit":100,"total":100}

 

#RequireAdmin
#include <AD.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <WinHttp.au3>
#include <FileConstants.au3>
#include <Misc.au3>
#include <StaticConstants.au3>
#include <File.au3>


AutoItSetOption("MustDeclareVars", 1)

Read()

;Function to read contents of the ZB_User WL ACL
Func Read()

;Kill Notepad++ if it is open
;If ProcessExists("notepad++.exe") Then ; Check if the Notepad++ process is running.
;   ProcessClose("notepad++.exe")
;EndIf

;Local $Page_Number = GUICtrlRead($WL_View_Entries_ZBUser_Page, $GUI_READ_EXTENDED)

For $i = 1 to 2 ;$Page_Number

Local $Domain = "https://management.api.umbrella.com/"
Local $Page = "v1/organizations/123/destinationlists/456/destinations/?page="& $i &"&limit=100"
MsgBox (64,"", "" & $Page)
;MsgBox (64,"", "" & $i)

Local $hOpen = _winhttpOpen()
If @error Then
    Exit 1
EndIf

Local $hConnect = _winhttpConnect($hOpen, $Domain)
If @error Then
    _WinHttpCloseHandle($hOpen)
    Exit 2
EndIf

Local $hRequest = _WinHttpSimpleSendSSLRequest($hConnect, "GET", $Page)
_WinHttpAddRequestHeaders($hConnect, "Accept: application/json")
_WinHttpAddRequestHeaders($hRequest, "Authorization: Basic 123")

If @error Then
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)
    Exit 3
EndIf

;Send the request
_WinHttpSendRequest($hRequest)
If @error Then
    MsgBox(48, "Error", "Error sending specified request.")
    _WinHttpCloseHandle($hRequest)
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)
    Exit 4
EndIf

; Wait for the response
_WinHttpReceiveResponse($hRequest)
If @error Then
    MsgBox(48, "Error", "Error waiting for the response from the server.")
    _WinHttpCloseHandle($hRequest)
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)
    Exit 5
EndIf

 Local $sChunk, $sData
; See what's returned
If _WinHttpQueryDataAvailable($hRequest) Then
    ;Local $sHeader = _WinHttpQueryHeaders($hRequest)
    ;ConsoleWrite($sHeader & @CRLF);Show the header in console
    ;MsgBox(4096, "Header", $sHeader);Show the header in MsgBox
    ;Read

    While 1
        $sChunk = _WinHttpReadData($hRequest)
        If @error Then ExitLoop
        $sData &= $sChunk
    WEnd
    ConsoleWrite($sData & @CRLF) ;Show the data in console
    ;MsgBox(4096, "Data", $sHeader & $sData) ;Show the data in MsgBox
Else
    MsgBox(48, "Error", "Site is experiencing problems.")
EndIf

_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)


Next

EndFunc

 

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...