Jump to content
Surya

Convert Curl code to winhttp request

Recommended Posts

Surya

Hi everyone its been loooong since I posted here :D:lol:

I have been trying to convert this curl executable parameters into autoit using the winhttp com object;

curl -F data_file=@my_audio_file.mp3 -F model=en-US "https://api.speechmatics.com/v1.0/user/41049/jobs/?auth_token=MmQ5MTk4jdsgjhgghstOGU5YS00OWFhLWghdgjshgdhbshj017###"

any ideas guys:D:)

 

PS: I am excited to post here after a looong time:lol:


No matter whatever the challenge maybe control on the outcome its on you its always have been.

MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition)

Share this post


Link to post
Share on other sites
TheXman
Posted (edited)
On 7/2/2018 at 11:20 AM, Surya said:

I have been trying to convert this curl executable parameters into autoit using the winhttp com object

Where is your attempt so that we can see where you are having a problem and give you some advice or guidance?

 

Edited by TheXman
Removed part about bumping post.

Whoever said that there's no such thing as a dumb question, probably asked a lot of DUMB questions.  Dumb questions are ones that you can easily find the answer to on your own.

Share this post


Link to post
Share on other sites
Surya

hi @TheXman I am very  poor in winhttp handling this is were I have reached ,I don't know wether it is right or not

Local $sServerURL = "https://api.speechmatics.com/v1.0/user/41049/jobs/?auth_token=MmQ5MTk4ZjQtOGU5YS00OWFhLWI3YzUtOWZkMDYwZWI3Zjg0"
Local $boundary = "--------Boundary"

Local $Postdata = "--" & $boundary & @CRLF & _
"Content-Disposition: form-data; model=en-US; data_file=" & '"' & filename($filepath) & '"' & @CRLF & _
"Content-Type: data_file" & @CRLF & @CRLF & _
Binary(FileRead($filepath)) & @CRLF & _
"--" & $boundary & "--" & @CRLF



Local $oHTTP = ObjCreate('winhttp.winhttprequest.5.1')
$oHTTP.Open("POST", $sServerURL, False)
$oHTTP.SetRequestHeader("Content-Type", "multipart/form-data; " & "boundary=" & $boundary)
$oHTTP.Send("model=en-US; data_file=" &Binary(FileRead($filepath)));$Postdata)
$hotlink = $oHTTP.ResponseText

 


No matter whatever the challenge maybe control on the outcome its on you its always have been.

MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition)

Share this post


Link to post
Share on other sites
TheXman

Here is a good example of one way to do a POST that uploads a file:

 

It uses winhttp.au3.  You can find a link the latest version of winhttp.au3 using the link below.  The zip file includes documentation that explains the winhttp.au3 functions and has several examples.

 

Assuming that you are calling the Speechmatic API correctly, this should get you closer to your goal.  If you run into an obstacles implementing the API using the example above, post back and we'll see if we can help you get past it.

 


Whoever said that there's no such thing as a dumb question, probably asked a lot of DUMB questions.  Dumb questions are ones that you can easily find the answer to on your own.

Share this post


Link to post
Share on other sites
Danyfirex

Hello Using WinHttp UDF you could do this:

#include "WinHTTP.au3"
Global Const $sFileToUpload = "C:\Users\Raziel\Desktop\WinHttp\test.mp3" ;<- Set correct file location here
Global Const $sAddress = "https://api.speechmatics.com/v1.0/user/41049/jobs/?auth_token=MmQ5MTk4jdsgjhgghstOGU5YS00OWFhLWghdgjshgdhbshj017###" ;<- Set correct host here

Local $sForm = _
        '<form action="' & $sAddress & '" method="post" enctype="multipart/form-data">' & _
        '    <input type="file" name="data_file" />' & _
        '    <input type="submit" name="model" value="en-US">' & _
        '</form>'

; Initialize and get session handle
$hOpen = _WinHttpOpen()

$hForm = $sForm

; Fill form on this page
$sRead = _WinHttpSimpleFormFill($hForm, $hOpen, Default, "name:data_file", $sFileToUpload)

; Close connection handle
_WinHttpCloseHandle($hForm)
; Close session handle
_WinHttpCloseHandle($hOpen)

; See what's returned (in default browser or whatever)
If $sRead Then
    ConsoleWrite($sRead & @CRLF)
EndIf

Saludos

Share this post


Link to post
Share on other sites
TheXman

.

Edited by TheXman
Removed content of my reply because it didn't add anyhting to the topic..

Whoever said that there's no such thing as a dumb question, probably asked a lot of DUMB questions.  Dumb questions are ones that you can easily find the answer to on your own.

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  
       
    • 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
×