Jump to content
Simpel

Again WinHTTP and Proxy

Recommended Posts

Simpel

Hi there.

I'm testing this code:

#include "WinHttp.au3"

; http://www.w3schools.com/php/demo_form_validation_escapechar.php
$sUserName = "SomeUserName"
$sEmail = "some.email@something.com"
$sDomain = "www.w3schools.com"
$sPage = "/php/demo_form_validation_escapechar.php"

; Data to send
$sAdditionalData = "name=" & $sUserName & "&email=" & $sEmail

; Initialize and get session handle
$hOpen = _WinHttpOpen("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hOpen = ' & $hOpen & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

; Get connection handle
$hConnect = _WinHttpConnect($hOpen, $sDomain)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hConnect = ' & $hConnect & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

; Make a request
$hRequest = _WinHttpOpenRequest($hConnect, "POST", $sPage)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hRequest = ' & $hRequest & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

; Send it. Specify additional data to send too. This is required by the Google API:
$hSendRequest = _WinHttpSendRequest($hRequest, "Content-Type: application/x-www-form-urlencoded", $sAdditionalData)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hSendRequest = ' & $hSendRequest & @CRLF & '>Error code: ' & @error & @TAB & "@extended: " & @extended & @CRLF) ;### Debug Console

; Wait for the response
$hReceiveResponse = _WinHttpReceiveResponse($hRequest)

; See what's returned
Dim $sReturned
If _WinHttpQueryDataAvailable($hRequest) Then ; if there is data
    Do
        $sReturned &= _WinHttpReadData($hRequest)
    Until @error
EndIf

; Close handles
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

; See what's returned
ConsoleWrite("Returned: " & $sReturned & @CRLF)

But sending a request fails.

Console outputs this:

>Running:(3.3.12.0) ...
--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
@@ Debug(14) : $hOpen = 0x00000000007DF540
>Error code: 0
@@ Debug(18) : $hConnect = 0x00000000008271C0
>Error code: 0
@@ Debug(22) : $hRequest = 0x00000000008B88E0
>Error code: 0
@@ Debug(26) : $hSendRequest = 0
>Error code: 1 @extended: 0
Returned:
+>17:00:18 AutoIt3.exe ended.rc:0
+>17:00:18 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 0.6003

I'm testing it at work. There, we always have to identify at a proxy to be allowed to go to internet. But requests via inet.au3 will work. Maybe our firewall will block the request?

Any ideas? I don't have any possibilities to test at home, because of OSX.

 

Regards, Conrad

Edited by Simpel
formating code + [Solved] + Problem again

SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win7Pro SP1   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Share this post


Link to post
Share on other sites
trancexx

If you need to identify proxy IE uses then you can use _WinHttpGetIEProxyConfigForCurrentUser() function.

;...
$aIEproxy = _WinHttpGetIEProxyConfigForCurrentUser()
$sProxy = $aIEproxy[2]

$hOpen = _WinHttpOpen("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0", $WINHTTP_ACCESS_TYPE_NAMED_PROXY, $sProxy)
;...

 


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
Simpel
_ArrayDisplay($aIEproxy)

says:

[0]         1
[1]
[2]
[3]

and:

ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sProxy = ' & $sProxy & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

says:

@@ Debug(15) : $sProxy = 
@@ Debug(21) : $hOpen = 0
>Error code: 0

$aIEproxy[0] = 1 means autodetect, correct? If I now try your modified "$hOpen" it's not working.


SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win7Pro SP1   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Share this post


Link to post
Share on other sites
trancexx

AutoDetect 1 means IE doesn't use PAC.
If you get no-proxy, like you do then that's not the way to go.

How do yo identify yourself for proxy?

 


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
Simpel

ipconfig /all replies

WINS-Proxy activated - NO

If I use intranet I'm always fine. When I want to use internet connection I first have to type in username and password.


SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win7Pro SP1   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Share this post


Link to post
Share on other sites
trancexx

Type in where?

Do you open some site in IE or what?


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
Simpel

Yes.

If I open a site in IE or FF. FF says something like: "Proxy moz-proxy://xxxprx01.xxx-xxx.de:8080 Needs username and password".


SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win7Pro SP1   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Share this post


Link to post
Share on other sites
Simpel
$sProxy = "xxxprx01.xxx-xxx.de:8080"

Now I'm a bit forward. $hSendRequest includes now "credentials are missing - username and password". Fine.

How to put username and password into the proxy variable? "USERNAME:PASSWORD@xxxprx01.xxx-xxx.de:8080" is not working.


SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win7Pro SP1   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Share this post


Link to post
Share on other sites
trancexx

My guess you are dealing with proxy that supports session based authentication. That means that for every session you have to authenticate.
If that's true you need to extend _WinHttpOpen() and add authentication routine. Like this maybe:

#include "WinHttp.au3"

Global Const $sAddress = "http://xxxprx01.xxx-xxx.de:8080" ; address of your proxy that requires authorization

; Credentials
Global Const $sUserName = "user", $sPassword = "password"
; Open session (with credentials from above)
Global $hOpen = OpenProxySession($sAddress)


; Try some site now
$hConnect = _WinHttpConnect($hOpen, "http://google.com")
; Simple-request it...
MsgBox(64, "Returned (first 1400 characters of google.com)", StringLeft(_WinHttpSimpleRequest($hConnect), 1400) & "...")
; Close handle
_WinHttpCloseHandle($hConnect)


; Finally close session
_WinHttpCloseHandle($hOpen)



Func OpenProxySession($sAddress)
    ; Initialize and get session handle
    Local $hOpen = _WinHttpOpen()
    If $hOpen Then
        ; Get connection handle
        Local $hConnect = _WinHttpConnect($hOpen, $sAddress)

        If $hConnect Then
            ; Specify the reguest
            Local $hRequest = _WinHttpOpenRequest($hConnect)
            If $hRequest Then
                ; Send the request
                _WinHttpSendRequest($hRequest)

                ; Wait for the response
                _WinHttpReceiveResponse($hRequest)

                ; Query status code
                Local $iStatusCode = _WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_STATUS_CODE)
                ; Check status code
                If $iStatusCode = $HTTP_STATUS_DENIED Or $iStatusCode = $HTTP_STATUS_PROXY_AUTH_REQ Then
                    ; Query Authorization scheme
                    Local $iSupportedSchemes, $iFirstScheme, $iAuthTarget
                    If _WinHttpQueryAuthSchemes($hRequest, $iSupportedSchemes, $iFirstScheme, $iAuthTarget) Then
                        ; Set passed credentials
                        _WinHttpSetCredentials($hRequest, $iAuthTarget, $iFirstScheme, $sUserName, $sPassword)
                        ; Send request again now
                        _WinHttpSendRequest($hRequest)
                        ; And wait for the response again
                        _WinHttpReceiveResponse($hRequest)
                        ; Excellent. You should be in if credentials were ok!!!
                    EndIf
                EndIf
                _WinHttpCloseHandle($hRequest)
            EndIf
            _WinHttpCloseHandle($hConnect)
        EndIf
    EndIf
    ; Return session handle
    Return $hOpen
EndFunc

But that's really only my guess.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
trancexx

Scratch that, this should work:

#include "WinHttp.au3"

Global Const $sProxy = "http://xxxprx01.xxx-xxx.de:8080" ; address of your proxy that requires authorization
; Credentials
Global Const $sUserName = "username", $sPassword = "password" ; set correct 

; Open session
Global $hOpen = _WinHttpOpen("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240", $WINHTTP_ACCESS_TYPE_NAMED_PROXY, $sProxy)
;~ _WinHttpSetOption($hOpen, $WINHTTP_OPTION_REDIRECT_POLICY, $WINHTTP_OPTION_REDIRECT_POLICY_NEVER)

; Try some site now
$hConnect = _WinHttpConnect($hOpen, "http://www.w3.org/")

$hRequest = _WinHttpSimpleSendRequest_ProxyAuth($hConnect)
; Simple-read...
MsgBox(4096, "http://www.w3.org/ says", _WinHttpSimpleReadData($hRequest))


; Close handles
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)



Func _WinHttpSimpleSendRequest_ProxyAuth($hConnect, $sType = Default, $sPath = Default, $sReferrer = Default, $sDta = Default, $sHeader = Default)
    ; Specify the reguest
    Local $hRequest = _WinHttpSimpleSendRequest($hConnect, $sType, $sPath, $sReferrer, $sDta, $sHeader)
    If $hRequest Then
        ConsoleWrite(_WinHttpQueryHeaders($hRequest) & @CRLF) ; let's print what the proxy says
        ; Query status code
        Local $iStatusCode = _WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_STATUS_CODE)
        ; Check status code
        If $iStatusCode = $HTTP_STATUS_PROXY_AUTH_REQ Then
            ; Query Authorization scheme
            Local $iSupportedSchemes, $iFirstScheme, $iAuthTarget
            If _WinHttpQueryAuthSchemes($hRequest, $iSupportedSchemes, $iFirstScheme, $iAuthTarget) Then
                ; Set passed credentials
                _WinHttpSetCredentials($hRequest, $iAuthTarget, $iFirstScheme, $sUserName, $sPassword)
                ; Send request again now
                _WinHttpSendRequest($hRequest)
                ; And wait for the response again
                _WinHttpReceiveResponse($hRequest)
                ; Excellent. You should be in if credentials were ok!!!
            EndIf
        EndIf
    EndIf
    Return $hRequest
EndFunc

However I'm not sure what will happen if you "open" address that redirects to another address. Proxy I tested this with doesn't cache credentials, and therefore redirects fail. If that would happen to you then uncomment the line below _WinHttpOpen() and test it again.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
Simpel

Thank you. It's working.

Sorry for delay. I had to test it under various conditions. And it took me a long time to understand how WinHttp.au3 and your snippet works.

Sometimes my code was running and then with little changes not.

Thanks and regards, Conrad


SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win7Pro SP1   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Share this post


Link to post
Share on other sites
Simpel

Hi,

now it's broken. They changed something. This is your code modified by me:

#include "WinHttp.au3"

Global Const $sProxy = "http://PROXY:8080" ; address of your proxy that requires authorization
; Credentials
Global Const $sUserName = "USER", $sPassword = "PASSWORD" ; set correct

; Open session
Global $hOpen = _WinHttpOpen("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240", $WINHTTP_ACCESS_TYPE_NAMED_PROXY, $sProxy)
;~ _WinHttpSetOption($hOpen, $WINHTTP_OPTION_REDIRECT_POLICY, $WINHTTP_OPTION_REDIRECT_POLICY_NEVER)

; Try some site now
$hConnect = _WinHttpConnect($hOpen, "http://posttestserver.com")

$hRequest = _WinHttpSimpleSendRequest_ProxyAuth($hConnect)
; Simple-read...
MsgBox(4096, "http://posttestserver.com/ says", _WinHttpSimpleReadData($hRequest))

$msg = _POST()
MsgBox(0, '', $msg)
ClipPut($msg)
Exit

; Close handles
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

Func _POST()
   Local $sData = ("Something to test and post.")
   Local $vRequest = _WinHttpSimpleRequest($hConnect, "POST", "http://posttestserver.com/post.php", $WINHTTP_NO_REFERER, $sData, "Content-Type: application/x-www-form-urlencoded")
   If @error Then Return "Unable To Send Request"
   Return $vRequest
EndFunc

Func _WinHttpSimpleSendRequest_ProxyAuth($hConnect, $sType = Default, $sPath = Default, $sReferrer = Default, $sDta = Default, $sHeader = Default)
    ; Specify the reguest
    Local $hRequest = _WinHttpSimpleSendRequest($hConnect, $sType, $sPath, $sReferrer, $sDta, $sHeader)
    If $hRequest Then
;~         ConsoleWrite(_WinHttpQueryHeaders($hRequest) & @CRLF) ; let's print what the proxy says
        ; Query status code
        Local $iStatusCode = _WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_STATUS_CODE)
        ; Check status code
        If $iStatusCode = $HTTP_STATUS_PROXY_AUTH_REQ Then
            ; Query Authorization scheme
            Local $iSupportedSchemes, $iFirstScheme, $iAuthTarget
            If _WinHttpQueryAuthSchemes($hRequest, $iSupportedSchemes, $iFirstScheme, $iAuthTarget) Then
                ; Set passed credentials
                _WinHttpSetCredentials($hRequest, $iAuthTarget, $iFirstScheme, $sUserName, $sPassword)
                ; Send request again now
                _WinHttpSendRequest($hRequest)
                ; And wait for the response again
                _WinHttpReceiveResponse($hRequest)
                ; Excellent. You should be in if credentials were ok!!!
            EndIf
        EndIf
    EndIf
    Return $hRequest
EndFunc

The output my clipboard contains:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<!-- FileName: index.html
     Language: [en]
-->
<!--Head-->
<head>
  <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  <meta http-equiv="X-UA-Compatible" content="IE=7" />
  <title>Proxy Message</title>
  <script src="/mwg-internal/de5fs23hu73ds/files/javascript/sw.js" type="text/javascript" ></script>
  <link rel="stylesheet" href="/mwg-internal/de5fs23hu73ds/files/default/stylesheet.css" />
</head>
<!--/Head-->
<!--Body-->
<body onload="swOnLoad();">
  <table class='bodyTable'>
    <tr>
      <td class='bodyData' background='/mwg-internal/de5fs23hu73ds/files/default/img/bg_body.gif'>
<!--Logo-->
<table class='logoTable'>
  <tr>
    <td class='logoData'>
      <a href='http://www.xxxxxxxxxxxxxxx.de'>
        <img src='/mwg-internal/de5fs23hu73ds/files/default/img/logo_mwg.png'></a>
    </td>
  </tr>
</table>
<!--/Logo-->
<!--Contents-->
<!-- FileName: authenticationrequired.html
     Language: [en]
-->
<!--Title-->
<table class='titleTable' background='/mwg-internal/de5fs23hu73ds/files/default/img/bg_navbar.jpg'>
  <tr>
    <td class='titleData'>
      Authentication Required
    </td>
  </tr>
</table>
<!--/Title-->

<!--Content-->
<table class="contentTable">
  <tr>
    <td class="contentData">
      You must be authenticated to access this URL.
    </td>
  </tr>
</table>
    
<script language="javascript" type="text/javascript">
   urlprotocol = "http";
   statuscode=407;

   if(statuscode==401 && urlprotocol == "ftp"){
      document.write("<form name=\"ftpform\" method=\"get\" action=\"\">");
      document.write("<table class=\"contentData\">");
      document.write("<tr><td class=\"contentData\" colspan=2>Please enter your credentials in the form below and click \"Access FTP\" button if your browser doesn't present authentication promt for FTP sites.</td></tr>");
      document.write("<tr><td class=\"contentData\">Username:</td><td><input type=\"text\" id=\"ftpUsername\" name=\"ftpUsername\" size=40 /></td></tr>");
      document.write("<tr><td class=\"contentData\">Password:</td><td><input type=\"password\" id=\"ftpPassword\" name=\"ftpPassword\" size=40 /></td></tr>");
      document.write("<tr><td class=\"contentData\" colspan=2 align=center><input type=\"button\" onclick=\"redirectToFTP();\" value=\"Access FTP\" /></td></tr>");
      document.write("</table>");
      document.write("</form>");
   }
   
   function redirectToFTP(){
      var username=escape(document.getElementById("ftpUsername").value);
      var password=escape(document.getElementById("ftpPassword").value);
      location.href = "ftp://"+username+":"+password+"@posttestserver.com:80/http://posttestserver.com/post.php"
   }
</script>
<!--/Content-->

<!--Info-->
<table class="infoTable">
  <tr>
    <td class="infoData">
      <b>URL: </b><script type="text/javascript">break_line("http://posttestserver.com/http://posttestserver.com/post.php");</script><br />
    </td>
  </tr>
</table>
<!--/Info-->

<!--/Contents-->
<!--Policy-->
<table class='policyTable'>
  <tr>
    <td class='policyHeading'>
      <hr>
      Company Acceptable Use Policy
    </td>
  </tr>
  <tr>
    <td class='policyData'>
      This is an optional acceptable use disclaimer that appears on every page. You may change the wording or remove this section entirely in index.html.
    </td>
  </tr>
</table>
<!--/Policy-->
<!--Foot-->
<table class='footTable'>
  <tr>
    <td class='helpDeskData' background='/mwg-internal/de5fs23hu73ds/files/default/img/bg_navbar.jpg'>
      For assistance, please contact your system administrator.
    </td>
  </tr>
  <tr>
    <td class='footData'>
      generated <span id="time">2016-05-09 21:46:25</span> by McAfee Web Gateway
      <br />
<br />
      Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240
    </td>
  </tr>
</table>
<!--/Foot-->
      </td>
    </tr>
  </table>
</body>
<!--/Body-->
</html>

_WinHttpSimpleReadData is working _WinHttpSimpleRequest not. What's wrong?

Regards, Conrad

Edited by Simpel

SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win7Pro SP1   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Share this post


Link to post
Share on other sites

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

  • Similar Content

    • Ascer
      By Ascer
      Hello
      Opertation Sys: Win7 x64
      Problem: Connecting to webs using TLS 1.1 +
      Description: WinHttp.WinHttpRequest.5.1 using TLS 1.0 by default, i need higher version to connect into some webs.
      Dim $oHttp = ObjCreate("WinHTTP.WinHTTPRequest.5.1") $oHttp.open ("GET", "https://howsmyssl.com/a/check", False) $oHttp.Option(9) = 128 ; 128 - TLS 1.0, 512 - TLS 1.1, 2048 - TLS 1.2, 2056 - TLS 1.1 & TLS 1.2 $oHttp.Send ConsoleWrite($oHttp.responseText & @CRLF) ; at end of the respond you can check your TLS version. Mine is: {"tls_version":"TLS 1.0","rating":"Bad"} Error: $oHttp.Option works only with parameter 128 (TLS 1.0) other values make error {Bad parameter}
      Additional: I've done this tutorial about enabling TLS in registry: <link>
      Thanks for support.
      Ascer
    • islandspapand
      By islandspapand
      Hi All
      i am currently trying to add a function to my project that can send SMS, i have gone with Twilio for the sms service that use a REST API.
      I have never worked with an API before, and could use some help.
      I can get my function working with using cURL.exe and copy past command from the website with the following code. And thats great unfortunately i am have issue with character like æøå when sending a SMS appears like a box or ?. this does not happen if i do it from the website so it looks like a Unicode issue in curl.exe.
      I have done some searching on the forum and understand that i should be able to implement this curl command with the WinHTTP UDF from @trancexx so i don't need a third part exe and it might fix my charater issue.
      Unfortunately i really don't understand how i am to change curl commands to the WinHTTP and i was hoping some good maybe give me an example i could learn from.
      Thanks in advanced
      i have removed the AuthToken number from the script.
      _SendSMS("00000000","SomeOne","SMS body info") Func _SendSMS($SendTo,$SendFrom,$Msgtxt) $AccountSID = "ACbb765b3180d5938229eff8b8f63ed1bc" $AuthToken = "Auth Token number" $Data = '"https://api.twilio.com/2010-04-01/Accounts/'&$AccountSID&'/Messages.json"'& _ '-X POST \ --data-urlencode "To=+45'&$SendTo&'" \ --data-urlencode "From='&$SendFrom&'" \ --data-urlencode "Body='&$Msgtxt&'" \ -u '&$AccountSID&':'&$AuthToken&'' ShellExecute(@ScriptDir&"\curl.exe","-k "&$Data) ;~ curl 'https://api.twilio.com/2010-04-01/Accounts/ACbb765b3180d5938229eff8b8f63ed1bc/Messages.json' -X POST \ ;~ --data-urlencode 'To=+4500000000' \ ;~ --data-urlencode 'From=Reception' \ ;~ --data-urlencode 'Body=Test Body' \ ;~ -u ACbb765b3180d5938229eff8b8f63ed1bc:[AuthToken] EndFunc  
       
    • ripdad
      By ripdad

      This script is based on algorithm code from EnrMa.
      Updated: January 22, 2018
      Made improvements. Changes are in the script header.
      Known Issues: AutoIt x64 does not work properly with this script.
      Download: LocalProxyServer_v1.00.zip
       
    • jesus40
      By jesus40
      Hello friends, i have a working curl command that show informations about my account on binance.com, but_it dont work with autoit code without curl.exe.
      I want to do it without curl, because the whole process much Slower_ with StdoutRead (I want get the response in variable.)
      My Curl command in Autoit:
      This 2 are works, but_ i would like to do it without curl.exe
      $apikey="XYZ" sCommand = @ScriptDir & '\curl.exe -k -H "X-MBX-APIKEY: ' & $apikey & '" -X GET "https://api.binance.com/api/v3/account?' & $request the same in .bat  file
      curl.exe -k -H "X-MBX-APIKEY: XYZ" -X GET "https://api.binance.com/api/v3/account?timestamp=1514917812000&signature=85bdee77e53cd521e1d5229fbfb459d53799c42b3fa4596d73f1520fad5f965a" (I use curl with -k option which allows curl to make insecure connections, because there is problem with the sites certificate, (cURL error 60))
       
      I tried many variations, this is the latest... I cant get the same response.
      curl $error message (I changed ): {"code":-2015,"msg":"Invalid API-key, IP, or permissions for action."}
      autoit version $error message (Response code:400): Mandatory parameter 'timestamp' was not sent, was empty/null, or malformed.
       
      $request = $query & '&signature=' & $signature $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("GET", "https://api.binance.com/api/v3/account", False) $oHTTP.SetRequestHeader("X-MBX-APIKEY", $apikey) $oHTTP.Send($request) $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status If $oStatusCode <> 200 then MsgBox(4096, "Response code", $oStatusCode) EndIf  
      thanks
    • AlwaysLearning
      By AlwaysLearning
      Hello,
      I have been struggling with this for nearly 20 hours, and I just cannot seem to figure out the formatting for the header request.
      To test this, you will need to use this api key I set up for your testing purposes. (note, I sent tracexx a direct message about this as I didn't realize I could limit API restrictions until just now, so I am now hoping on of you may have the answer on hand)
      I need to be able to GET balance and POST orders.
      Right now, I can't get past the 401/403 errors on my own.
      I believe the Content is formatted for JSON, but using the JSON format didn't work for me ( although that may be because I'm an idiot and formatted something wrong).
      I want to get:
      GET balance page POST delete order page Here is a temporary API key + Secret API key with only the "View Balance Page" and "Delete Order" functions enabled:
      Access-key: tq6GeUrEvfxyF-LG
      Secret Access-Key: cZlz75K1wb8-Ed67pRaXvUWTPW6RTH9q

      Here is the site's API guide (I followed this closely and doubt the error is there): https://coincheck.com/documents/exchange/api#libraries
       
      And here is running source code (needs those keys inputted) which will hash the above keys to the required HMAC SHA256:
      #include <Crypt.au3> #include<WinHttp.au3> Global Const $CALG_SHA_256 = 0x0000800c ;; ===== $api = "/api/accounts/balance" $accessNonCE = _TimeGetStamp() $url = "https://coincheck.com/api/accounts/balance" $body = "" WinHTTP($url, $body) Func WinHTTP($sUrl, $sBody) Local $hOpen = _WinHttpOpen() Local $hConnect = _WinHttpConnect($hOpen, "https://coincheck.com/api/accounts/balance") ; Specify the reguest: ;Local $hRequest = _WinHttpOpenRequest($hConnect, Default, $sApi) $accessKey = "" ;; Add the key from above $secretKey = "" ;; Add the secret key from above $message = $accessNonCE & $sUrl $BinarySignature = HMAC($secretKey, $message) $signature = _Base64Encode($BinarySignature) ;Encode signature Local $hRequest = _WinHttpOpenRequest($hConnect, "GET") _WinHttpAddRequestHeaders($hRequest, 'ACCESS-KEY: '&$accessKey) _WinHttpAddRequestHeaders($hRequest, 'ACCESS-NONCE: '&$accessNonCE) _WinHttpAddRequestHeaders($hRequest, 'ACCESS-SIGNATURE: '&$signature) ; Send request _WinHttpSendRequest($hRequest) ; Wait for the response _WinHttpReceiveResponse($hRequest) Local $sHeader = _WinHttpQueryHeaders($hRequest) ; ...get full header Local $sData = _WinHttpReadData($hRequest) ; Clean _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) ; Display retrieved data MsgBox(0, "Data", $sData) EndFunc Func sha256($message) Return _Crypt_HashData($message, $CALG_SHA_256) EndFunc Func HMAC($key, $message, $hash="sha256") Local $blocksize = 64 Local $a_opad[$blocksize], $a_ipad[$blocksize] Local Const $oconst = 0x5C, $iconst = 0x36 Local $opad = Binary(''), $ipad = Binary('') $key = Binary($key) If BinaryLen($key) > $blocksize Then $key = Call($hash, $key) For $i = 1 To BinaryLen($key) $a_ipad[$i-1] = Number(BinaryMid($key, $i, 1)) $a_opad[$i-1] = Number(BinaryMid($key, $i, 1)) Next For $i = 0 To $blocksize - 1 $a_opad[$i] = BitXOR($a_opad[$i], $oconst) $a_ipad[$i] = BitXOR($a_ipad[$i], $iconst) Next For $i = 0 To $blocksize - 1 $ipad &= Binary('0x' & Hex($a_ipad[$i],2)) $opad &= Binary('0x' & Hex($a_opad[$i],2)) Next Return Call($hash, $opad & Call($hash, $ipad & Binary($message))) EndFunc Func _TimeGetStamp() Local $av_Time $av_Time = DllCall('CrtDll.dll', 'long:cdecl', 'time', 'ptr', 0) If @error Then SetError(99) Return False EndIf Return $av_Time[0] EndFunc Func _Base64Encode($input) $input = Binary($input) Local $struct = DllStructCreate("byte[" & BinaryLen($input) & "]") DllStructSetData($struct, 1, $input) Local $strc = DllStructCreate("int") Local $a_Call = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _ "ptr", DllStructGetPtr($struct), _ "int", DllStructGetSize($struct), _ "int", 1, _ "ptr", 0, _ "ptr", DllStructGetPtr($strc)) If @error Or Not $a_Call[0] Then Return SetError(1, 0, "") ; error calculating the length of the buffer needed EndIf Local $a = DllStructCreate("char[" & DllStructGetData($strc, 1) & "]") $a_Call = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _ "ptr", DllStructGetPtr($struct), _ "int", DllStructGetSize($struct), _ "int", 1, _ "ptr", DllStructGetPtr($a), _ "ptr", DllStructGetPtr($strc)) If @error Or Not $a_Call[0] Then Return SetError(2, 0, ""); error encoding EndIf Return DllStructGetData($a, 1) EndFunc ;==>_Base64Encode
       
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.