Jump to content

WinHttp Post _WinHttpSimpleSSLRequest


Recommended Posts

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.


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

Global $hConnect = _winhttpConnect($hOpen, $Domain)
If @error Then
    Exit 2

$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
    Exit 3

;Send the request
If @error Then
    MsgBox(48, "Error", "Error sending specified request.")
    Exit 4

; Wait for the response
If @error Then
    MsgBox(48, "Error", "Error waiting for the response from the server.")
    Exit 5

 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
    ;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
    MsgBox(48, "Error", "Site is experiencing problems.")

;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

Func Close_request()
    ; Close open handles and exit








Link to comment
Share on other sites

  • 4 weeks later...

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