Jump to content

Remo_

Members
  • Posts

    7
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Remo_'s Achievements

Seeker

Seeker (1/7)

1

Reputation

  1. 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
  2. Tried that, . Here is the UDF, under $Type, I am only seeing GET or POST, no DELETE. ; #FUNCTION# ==================================================================================================================== ; Name...........: _WinHttpSimpleSSLRequest ; Description ...: A function to send a SSL request in a simpler form ; Syntax.........: _WinHttpSimpleSSLRequest($hConnect [, $sType [, $sPath [, $sReferrer = Default [, $sDta = Default [, $sHeader = Default [, $fGetHeaders = Default [, $iMode = Default ]]]]]]]) ; Parameters ....: $hConnect - Handle from _WinHttpConnect ; $sType - [optional] GET or POST (default: GET) ; $sPath - [optional] request path (default: "" - empty string; meaning 'default' page on the server) ; $sReferrer - [optional] referrer (default: $WINHTTP_NO_REFERER) ; $sDta - [optional] POST-Data (default: $WINHTTP_NO_REQUEST_DATA) ; $sHeader - [optional] additional Headers (default: $WINHTTP_NO_ADDITIONAL_HEADERS) ; $fGetHeaders - [optional] return response headers (default: False) ; $iMode - [optional] reading mode of result ; |0 - ASCII-text ; |1 - UTF-8 text ; |2 - binary data
  3. I am trying to send a delete method using HTTPS _WinHttpSimpleSSLRequest, I am not seeing the option in the UDF. Am I missing something? Global $hRequest = _WinHttpSimpleSSLRequest($hConnect,"POST", $sTarget, Default, $sDta, $sHeader, Default, Default, Default, Default, 1)
  4. ok, I found that this one line string works Global $sDta = '[{"destination":"testing99.com","comment":"COMMENT99"}]' Now I need to figure out how to replcae tesing99.com and COMMENT99 with $varibles. Fixed it, posting answer as it may help somone else. $URL = "testing1003.com" $Comment = "Comment1003" Global $sDta = '[{"destination":"' & $URL & _ '","comment":"' & $Comment & _ '"}]'
  5. API documentation was wrong.
  6. I am having issues sending a JSON string using winhttp if anyone can help me, thanks. The initial HTTP error I was getting is 400, error Bad Request. It should be array of destination objects",txid":"f5b74"} After formatting $sDta like below Global $sDta = '{' & _ '\"destination \":\"testadd99.com \", ' & _ '\"comment \":\"Comment99 \", ' & _ '}' I now get Response: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>Error: No default engine was specified and no extension was provided.<br> &nbsp; &nbsp;at new View (/usr/src/app/node_modules/express/lib/view.js:61:11)<br> &nbsp; &nbsp;at Function.render (/usr/src/app/node_modules/express/lib/application.js:570:12)<br> &nbsp; &nbsp;at ServerResponse.render (/usr/src/app/node_modules/express/lib/response.js:1008:7)<br> &nbsp; &nbsp;at /usr/src/app/dist/utils/securityheaders.js:41:13<br> &nbsp; &nbsp;at Layer.handle_error (/usr/src/app/node_modules/express/lib/router/layer.js:71:5)<br> &nbsp; &nbsp;at trim_prefix (/usr/src/app/node_modules/express/lib/router/index.js:315:13)<br> &nbsp; &nbsp;at /usr/src/app/node_modules/express/lib/router/index.js:284:7<br> &nbsp; &nbsp;at Function.process_params (/usr/src/app/node_modules/express/lib/router/index.js:335:12)<br> &nbsp; &nbsp;at next (/usr/src/app/node_modules/express/lib/router/index.js:275:10)<br> &nbsp; &nbsp;at Layer.handle_error (/usr/src/app/node_modules/express/lib/router/layer.js:67:12)</pre> </body> </html> Here is the code I am using. #include <WinHttp.au3> Global $Domain = "https://management.api.umbrella.com/" Global $sTarget = "v1/organizations/12345/destinationlists/54321/destinations" Global $sHeader = _ 'Authorization: Basic XYZ' & @CRLF & _ 'Accept: application/json' & @CRLF & _ 'Content-Type: application/json' Global $sDta = '{' & _ '\"destination \":\"testadd99.com \", ' & _ '\"comment \":\"Comment99 \", ' & _ '}' Global $hOpen = _winhttpOpen() If @error Then Exit 1 EndIf Global $hConnect = _winhttpConnect($hOpen, $Domain) If @error Then _WinHttpCloseHandle($hOpen) Exit 2 EndIf Global $hRequest = _WinHttpSimpleSSLRequest($hConnect,"POST", $sTarget, Default, $sDta, $sHeader, Default, Default, Default, Default, 1) ConsoleWrite("Response: "& $hRequest & @CRLF) If @error Then _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) Exit 3 EndIf ;Send the request _WinHttpSendRequest($hRequest) API documentation, https://docs.umbrella.com/umbrella-api/reference#post_v1-organizations-organizationid-destinationlists-destinationlistid-destinations
  7. Hi Everyone, I am struggling with the syntax using a post in _WinHttpSimpleSSLRequest, I am getting an @error exit. I am also unsure of the syntax $sdta should be in. Here is a link to the API post with several examples. https://docs.umbrella.com/destination-api/reference#post_v1-organizations-organizationid-destinationlists-destinationlistid-destinations Here is the code I have so far, I have a successfull GET working using the same code but with "Global $hRequest = _WinHttpSimpleSendSSLRequest($hConnect, "GET", $Page) " Thanks for any help #include "WinHttp.au3" #include <FileConstants.au3> Global $Domain = "https://management.api.umbrella.com/" Global $Page = "v1/organizations/1234567/destinationlists/7654321/destinations" Global $hOpen = _winhttpOpen() If @error Then Exit 1 EndIf Global $hConnect = _winhttpConnect($hOpen, $Domain) If @error Then _WinHttpCloseHandle($hOpen) Exit 2 EndIf $sDta = "[{\"destination\":\"testing1.com\",\"comment\":\"testing1.com COMMENT\"},{\"destination\":\"testing2.com\",\"comment\":\"testing2.com COMMENT\"}]"; $sHeader = 'Content-Type: application/json' Global $hRequest = _WinHttpSimpleSSLRequest($hConnect, "POST", $Page, Default, $sDta, $sHeader, True, 1) _WinHttpAddRequestHeaders($hConnect, "Accept: application/json") _WinHttpAddRequestHeaders($hRequest, "Authorization: Basic Key") ; Syntax.........: _WinHttpSimpleSSLRequest($hConnect [, $sType [, $sPath [, $sReferrer = Default [, $sDta = Default [, $sHeader = Default [, $fGetHeaders = Default [, $iMode = Default ]]]]]]]) ; Parameters ....: $hConnect - Handle from _WinHttpConnect ; $sType - [optional] GET or POST (default: GET) ; $sPath - [optional] request path (default: "" - empty string; meaning 'default' page on the server) ; $sReferrer - [optional] referrer (default: $WINHTTP_NO_REFERER) ; $sDta - [optional] POST-Data (default: $WINHTTP_NO_REQUEST_DATA) ; $sHeader - [optional] additional Headers (default: $WINHTTP_NO_ADDITIONAL_HEADERS) ; $fGetHeaders - [optional] return response headers (default: False) ; $iMode - [optional] reading mode of result ; |0 - ASCII-text ; |1 - UTF-8 text ; |2 - binary data 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.") Close_request() Exit 4 EndIf ; Wait for the response _WinHttpReceiveResponse($hRequest) If @error Then MsgBox(48, "Error", "Error waiting for the response from the server.") Close_request() Exit 5 EndIf Global $sChunk, $sData ; See what's returned If _WinHttpQueryDataAvailable($hRequest) Then Global $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", $sData) ;Show the data in MsgBox MsgBox(4096, "Data", $sHeader & $sData) ;Show the data in MsgBox Else MsgBox(48, "Error", "Site is experiencing problems.") EndIf Close_request() ;Create path the log file $sFilePath = (@ScriptDir & "\WriteResults.json") ;Open log file with overwrite flag Local $hFile = FileOpen($sFilePath, $FO_OVERWRITE ) ;Write date to log file FileWrite($hFile, $sData) ;Close the log file FileClose($hFile) Func Close_request() ; Close open handles and exit _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) EndFunc
×
×
  • Create New...