Jump to content

Convert Curl code to winhttp request


Recommended Posts

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)

Link to post
Share on other sites
  • 2 weeks later...
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.
Link to post
Share on other sites

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)

Link to post
Share on other sites

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.

 

Link to post
Share on other sites

Hello Using WinHttp UDF you could do this:

#include "WinHTTP.au3"
Global Const $sFileToUpload = "C:\Users\User\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

Edited by Danyfirex
Link to post
Share on other sites

.

Edited by TheXman
Removed content of my reply because it didn't add anyhting to the topic..
Link to post
Share on other sites
  • 2 weeks later...

voila everyone this is where I am I am unable to using winhttp it shows this

{
  "code": 400, 
  "error": "Missing data_file"
}
test.wav

 

this is the code

$filepath = FileOpenDialog("Select",@ScriptDir,"All (*.*)")
$filepah = FileOpen($filepath,16)
$output = AnonFilesUpload($filepath)

ConsoleWrite(filename($filepath) & @CRLF)
ConsoleWrite($output & @CRLF)

Func AnonFilesUpload($filepath)

 $sServerURL = "https://api.speechmatics.com/v1.0/user/41049/jobs/?auth_token=MmQ5MTk4ZjQtOGU5YS00OWFhLWI3YzUtOMDYwZWI4Zjg0"
 $boundary = "------------WinHttpBoundaryLine_96747.69683"
;"--" &$boundary  &@CRLF & _
 ; "Content-Disposition: form-data; name=" &'"model"; ' &' value="en-US"' &@CRLF & _
   ;"Content-Type: submit" &@CRLF & _
 $Postdata = "--" & $boundary & @CRLF & _
   "Content-Disposition: form-data; name=" &'"' &"data_file" &'"' &"; filename=" &'"' &filename($filepath) &'"' &@CRLF & _
   "Content-Type: audio/x-wav" & @CRLF & @CRLF & _
   BinaryToString(FileRead($filepah)) & @CRLF &@CRLF & _
   "--" & $boundary  &@CRLF & _
   'Content-Disposition: form-data; name="model"' &@CRLF &@CRLF & _
   'en-US' &@CRLF & _
   "--" & $boundary & "--" &@CRLF
MsgBox(Default,Default,$Postdata)

 $oHTTP = ObjCreate('winhttp.winhttprequest.5.1')
 $oHTTP.Open("POST", $sServerURL, False)
 $oHTTP.SetRequestHeader("Content-Type", "multipart/form-data; " & "boundary=" & $boundary)
 $oHTTP.SetRequestHeader("Accept","application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,*/*;q=0.5")
 $oHTTP.SetRequestHeader("Accept","utf-8;q=0.7")
 $oHTTP.Send($Postdata)
 $oHTTP.WaitForResponse()
 $hotlink = $oHTTP.ResponseText
 ConsoleWrite($hotlink)
 $hotlink = StringRegExpReplace(StringMid($hotlink, StringInStr($hotlink, "https")), '[/"}]', "")
   Return $hotlink
EndFunc

Func filename($filepath)
 Local $file = StringSplit($filepath, "\")
     Return $file[(UBound($file) - 1)]
EndFunc

I took the code from here 

and tried to modify it but it wont work,Can anyone please help me where I am wrong

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)

Link to post
Share on other sites
  • 3 weeks later...

 I made it till here what am I missing again

$filepath = FileOpenDialog("Select",@ScriptDir,"All (*.*)")
$filepah = FileOpen($filepath)
$output = AnonFilesUpload($filepath)

ConsoleWrite(filename($filepath) & @CRLF)
ConsoleWrite($output & @CRLF)

Func AnonFilesUpload($filepath)

 $sServerURL = "https://api.speechmatics.com/v1.0/user/41049/jobs/?auth_token=MmQ5MTk4ZjQtOGU5YS00OWFhUtOWZkMDYwZWI4Zjg0"
 $boundary = "------------WinHttpBoundaryLine_96747.69683"
;"--" &$boundary  &@CRLF & _
 ; "Content-Disposition: form-data; name=" &'"model"; ' &' value="en-US"' &@CRLF & _
   ;"Content-Type: submit" &@CRLF & _
 $Postdata = '--' & $boundary & @CRLF & _
   'Content-Disposition: form-data; name="model"' &@CRLF &@CRLF & _
   'en-US' &@CRLF & _
   '--' & $boundary &@CRLF & _
   'Content-Disposition: form-data; name="data_file"; filename=' &'"' &filename($filepath) &'"' &@CRLF & _
   'Content-Type: audio/x-wav' & @CRLF & @CRLF & _
    FileRead($filepah)   & @CRLF & _
   '--' & $boundary & '--'
   MsgBox(Default,Default,$Postdata)

 $oHTTP = ObjCreate('winhttp.winhttprequest.5.1')
 $oHTTP.Open("POST", $sServerURL, False)
 $oHTTP.SetRequestHeader("Content-Type", "multipart/form-data; boundary=" & $boundary)
 $oHTTP.SetRequestHeader("Accept","application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,*/*;q=0.5")
 $oHTTP.SetRequestHeader("Accept","utf-8;q=0.7")
$oHTTP.SetRequestHeader('Content-Length',StringLen($Postdata))
 $oHTTP.Send($Postdata)
 $oHTTP.WaitForResponse()
 $hotlink = $oHTTP.ResponseText
 ConsoleWrite($hotlink)
 $hotlink = StringRegExpReplace(StringMid($hotlink, StringInStr($hotlink, "https")), '[/"}]', "")
   Return $hotlink
EndFunc

Func filename($filepath)
 Local $file = StringSplit($filepath, "\")
     Return $file[(UBound($file) - 1)]
EndFunc

can someone help me..

while exexuting this i get this

--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
{
  "code": 403, 
  "error": "Job rejected due to invalid audio"
}
tmp.wav

+>08:33:04 AutoIt3.exe ended.rc:0
+>08:33:04 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 21.53

 

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)

Link to post
Share on other sites

Is there somewherw where i can learn this, anyone here hello,i tired googling and couldnt find anything all i could find was documentation of winhttp

Edited by Surya

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)

Link to post
Share on other sites

Does this work?

 

$filepath=@ScriptDir & "\test.mp3"
$sServerURL = "https://api.speechmatics.com/v1.0/user/41049/jobs/?auth_token=MmQ5MTk4ZjQtOGU5YS00OWFhUtOWZkMDYwZWI4Zjg0"
$boundary = "------WinHttpBoundaryLine_96747.69683"
;"--" &$boundary  &@CRLF & _
; "Content-Disposition: form-data; name=" &'"model"; ' &' value="en-US"' &@CRLF & _
;"Content-Type: submit" &@CRLF & _
$Postdata = $boundary & @CRLF & _
        'Content-Disposition: form-data; name="data_file"; filename="' & filename($filepath) & '"' & @CRLF & _
        'Content-Type: audio/mpeg' & @CRLF & @CRLF & _
        FileRead($filepath) & @CRLF & _
        $boundary  & @CRLF & _
        'Content-Disposition: form-data; name="model"' & @CRLF & @CRLF & _
        'en-US' & @CRLF & _
        $boundary & "--" & @CRLF



;~ ConsoleWrite($Postdata & @CRLF)
;~ Exit

$oHTTP = ObjCreate('winhttp.winhttprequest.5.1')
$oHTTP.Open("POST", $sServerURL, False)
$oHTTP.SetRequestHeader("Content-Type", 'multipart/form-data; boundary=----WinHttpBoundaryLine_51560.17967')
$oHTTP.SetRequestHeader("Accept", "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,*/*;q=0.5")
$oHTTP.SetRequestHeader("Accept-Charset", "utf-8;q=0.7")
$oHTTP.SetRequestHeader('Content-Length', StringLen($Postdata))
$oHTTP.Send($Postdata)
$oHTTP.WaitForResponse()
$hotlink = $oHTTP.ResponseText
ConsoleWrite($hotlink)

Func filename($filepath)
 Local $file = StringSplit($filepath, "\")
     Return $file[(UBound($file) - 1)]
EndFunc

Saludos

Link to post
Share on other sites

@Danyfirex it didn't work:(:'(:'(:'(

but the winhttp udf thing worked well,why doesn't the code work are we making any mistake or is it that my winhttp versions are not correct

I copy pasted ur code

screenshots attatched

Screenshot (16).png

Edited by Surya

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)

Link to post
Share on other sites

Hello. Here you have.

$filepath=@ScriptDir & "\zero.wav"
$sServerURL = "https://api.speechmatics.com/v1.0/user/41049/jobs/?auth_token=MmQ5MTk4ZjQtOGU5YS00OWFhLWI3YzUtOWZkMDYwZWI4Zjg0"
$boundary = "------WinHttpBoundaryLine_96747.69683"
$Postdata = $boundary & @CRLF & _
        'Content-Disposition: form-data; name="data_file"; filename="' & filename($filepath) & '"' & @CRLF & _
        'Content-Type: application/octet-stream' & @CRLF & @CRLF & _
        BinaryToString(FileRead($filepath)) & @CRLF & _
        $boundary  & @CRLF & _
        'Content-Disposition: form-data; name="model"' & @CRLF & @CRLF & _
        'en-US' & @CRLF & _
        $boundary & "--" & @CRLF


$oHTTP = ObjCreate('winhttp.winhttprequest.5.1')
$oHTTP.Open("POST", $sServerURL, False)
$oHTTP.SetRequestHeader("User-Agent", 'Mozilla/5.0 (Windows NT 10.0; WOW64) WinHttp/1.6.3.9 (WinHTTP/5.1) like Gecko')
$oHTTP.SetRequestHeader("Content-Type", 'multipart/form-data; boundary=----WinHttpBoundaryLine_96747.69683')
$oHTTP.SetRequestHeader("Accept", "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,*/*;q=0.5")
$oHTTP.SetRequestHeader("Accept-Charset", "utf-8;q=0.7")
$oHTTP.SetRequestHeader('Content-Length', StringLen($Postdata))
$oHTTP.Send(Binary($Postdata))
$oHTTP.WaitForResponse()
$hotlink = $oHTTP.ResponseText
ConsoleWrite($hotlink)

Func filename($filepath)
 Local $file = StringSplit($filepath, "\")
     Return $file[(UBound($file) - 1)]
EndFunc

Saludos

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By mLipok
      I try to download some file with winhttp.au3
      I use code from here:

      My code looks like:
      #include <FileConstants.au3> #include "WinHttp.au3" #AutoIt3Wrapper_Run_AU3Check=N _Example() Func _Example() ; Initialize and get session handle Local $hOpen = _WinHttpOpen() ; Get connection handle Local $hConnect = _WinHttpConnect($hOpen, "https://MY_URL") Local $CurrentOption = _WinHttpQueryOption($hConnect, $WINHTTP_OPTION_SECURITY_FLAGS) Local $Options = BitOR($CurrentOption, _ $SECURITY_FLAG_IGNORE_UNKNOWN_CA, _ $SECURITY_FLAG_IGNORE_CERT_CN_INVALID, _ $SECURITY_FLAG_IGNORE_CERT_DATE_INVALID) _WinHttpSetOption($hConnect, $WINHTTP_OPTION_SECURITY_FLAGS, $Options) If @error Then ConsoleWrite("! ---> @error=" & @error & " @extended=" & @extended & _ " : _WinHttpSetOption" & @CRLF) ; Specify the reguest Local $hRequest = _WinHttpOpenRequest($hConnect, Default, "MY_FILE") ; Send request _WinHttpSendRequest($hRequest) ; Wait for the response _WinHttpReceiveResponse($hRequest) ProgressOn("Downloading", "In Progress...") Progress(_WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_CONTENT_LENGTH)) Local $sData ; Check if there is data available... If _WinHttpQueryDataAvailable($hRequest) Then While 1 $sChunk = _WinHttpReadData_Ex($hRequest, Default, Default, Default, Progress) If @error Then ExitLoop $sData &= $sChunk Sleep(20) WEnd Else MsgBox(48, "Error", "Site is experiencing problems (or you).") EndIf Sleep(1000) ProgressOff() ; Close handles _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) Local $hFile = FileOpen(@ScriptDir & "\MY_FILE", $FO_OVERWRITE + $FO_CREATEPATH + $FO_BINARY) FileWrite($hFile, $sData) FileClose($hFile) EndFunc ;==>_Example Func Progress($iSizeAll, $iSizeChunk = 0) Local Static $iMax, $iCurrentSize If $iSizeAll Then $iMax = $iSizeAll $iCurrentSize += $iSizeChunk Local $iPercent = Round($iCurrentSize / $iMax * 100, 0) ProgressSet($iPercent, $iPercent & " %") EndFunc ;==>Progress Func _WinHttpReadData_Ex($hRequest, $iMode = Default, $iNumberOfBytesToRead = Default, $pBuffer = Default, $vFunc = Default) __WinHttpDefault($iMode, 0) __WinHttpDefault($iNumberOfBytesToRead, 8192) __WinHttpDefault($vFunc, 0) Local $tBuffer, $vOutOnError = "" If $iMode = 2 Then $vOutOnError = Binary($vOutOnError) Switch $iMode Case 1, 2 If $pBuffer And $pBuffer <> Default Then $tBuffer = DllStructCreate("byte[" & $iNumberOfBytesToRead & "]", $pBuffer) Else $tBuffer = DllStructCreate("byte[" & $iNumberOfBytesToRead & "]") EndIf Case Else $iMode = 0 If $pBuffer And $pBuffer <> Default Then $tBuffer = DllStructCreate("char[" & $iNumberOfBytesToRead & "]", $pBuffer) Else $tBuffer = DllStructCreate("char[" & $iNumberOfBytesToRead & "]") EndIf EndSwitch Local $sReadType = "dword*" If BitAND(_WinHttpQueryOption(_WinHttpQueryOption(_WinHttpQueryOption($hRequest, $WINHTTP_OPTION_PARENT_HANDLE), $WINHTTP_OPTION_PARENT_HANDLE), $WINHTTP_OPTION_CONTEXT_VALUE), $WINHTTP_FLAG_ASYNC) Then $sReadType = "ptr" Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpReadData", _ "handle", $hRequest, _ "struct*", $tBuffer, _ "dword", $iNumberOfBytesToRead, _ $sReadType, 0) If @error Or Not $aCall[0] Then Return SetError(1, 0, "") If Not $aCall[4] Then Return SetError(-1, 0, $vOutOnError) If IsFunc($vFunc) Then $vFunc(0, $aCall[4]) If $aCall[4] < $iNumberOfBytesToRead Then Switch $iMode Case 0 Return SetExtended($aCall[4], StringLeft(DllStructGetData($tBuffer, 1), $aCall[4])) Case 1 Return SetExtended($aCall[4], BinaryToString(BinaryMid(DllStructGetData($tBuffer, 1), 1, $aCall[4]), 4)) Case 2 Return SetExtended($aCall[4], BinaryMid(DllStructGetData($tBuffer, 1), 1, $aCall[4])) EndSwitch Else Switch $iMode Case 0, 2 Return SetExtended($aCall[4], DllStructGetData($tBuffer, 1)) Case 1 Return SetExtended($aCall[4], BinaryToString(DllStructGetData($tBuffer, 1), 4)) EndSwitch EndIf EndFunc ;==>_WinHttpReadData_Ex
      As a result I get file with this contents:
       
      As so far I found this:
        

      So I even with added:
      Local $CurrentOption = _WinHttpQueryOption($hConnect, $WINHTTP_OPTION_SECURITY_FLAGS) Local $Options = BitOR($CurrentOption, _ $SECURITY_FLAG_IGNORE_UNKNOWN_CA, _ $SECURITY_FLAG_IGNORE_CERT_CN_INVALID, _ $SECURITY_FLAG_IGNORE_CERT_DATE_INVALID) _WinHttpSetOption($hConnect, $WINHTTP_OPTION_SECURITY_FLAGS, $Options) If @error Then ConsoleWrite("! ---> @error=" & @error & " @extended=" & @extended & _ " : _WinHttpSetOption" & @CRLF)
      I still get the same errors.

      Anyone know a way how to fix this problem?

      Regards,
      mLipok
       
    • By adityaparakh
      Hello ,
      I am trying to use Websockets in AutoIt.
      It is to fetch live stock market prices , API is provided and documentation available for python language.
      The link for the code snippet is :
      https://symphonyfintech.com/xts-market-data-front-end-api-v2/#tag/Introduction
      https://symphonyfintech.com/xts-market-data-front-end-api-v2/#tag/Instruments/paths/~1instruments~1subscription/post
       
      https://github.com/symphonyfintech/xts-pythonclient-api-sdk
       
      Second Link is to subscribe to a list of ExchangeInstruments.
      Now I would like to get live stock ltp (LastTradedPrice) for a few stocks whose "ExchangeInstrumentID" I know.
      I am able to use the WinHttp object to perform actions using simple codes like below :
      I have the secretKey and appkey and can generate the needed token. And get the unique ExchangeInstrumentID.

      Below code is just for example of how I am using WinHttp. Unrelated to socket part.
      Global $InteractiveAPItoken = IniRead(@ScriptDir & "\Config.ini", "token", "InteractiveAPItoken", "NA") $baseurl = "https://brokerlink.com/interactive/" $functionurl = "orders" $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $baseurl & $functionurl, False) $oHTTP.SetRequestHeader("Content-Type", "application/json;charset=UTF-8") $oHTTP.SetRequestHeader("authorization", $InteractiveAPItoken) $pD = '{ "exchangeSegment": "NSEFO", "exchangeInstrumentID": ' & $exchangeInstrumentID & ', "productType": "' & $producttype & '", "orderType": "MARKET", "orderSide": "' & $orderside & '", "timeInForce": "DAY", "disclosedQuantity": 0, "orderQuantity": ' & $qty & ', "limitPrice": 0, "stopPrice": 0, "orderUniqueIdentifier": "' & $orderidentifier & '"}' $oHTTP.Send($pD) $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status
          
          
      But am struggling to understand and use socket.
      Would be of great help if you can have a look at the link mentioned above and help with the code sample for AutoIt.
      To connect and listen to a socket.
      Thanks a lot
       
    • By Mr_Microphone
      Alright, I may be an idiot.
      Three years ago, I wrote a program that pushed component information to a secure site via their API. I went back to add some attributes and (here's the idiot part) ended up losing the  source code and my modified code does not quite work. I have the compiled version that works minus the new attributes, so I know that their system has not changed. I stripped the larger program down from 3,000 lines to the part that is broken, but I am stumped. This was one of my first scripts, so it heavily leverages examples and isn't as pretty as I'd like it to be.
      Be gentle. 
      The program / script creates a new records as expected, but for some reason, I cannot access information in the response, which I need for a later step.
      I use Charles, a web debugging proxy tool so I can see the request and the response and both are as expected. Also, when I write to log file, the JSON reply is exactly what I expect and need, but when I try to do anything with the http body, it seems to be blank. 
      Here is the script minus  the URL and token:
      #include <Array.au3> #include <Curl.au3> #include <MsgBoxConstants.au3> #include <json.au3>  ; this was added as an alternate way to read the data Global $WM_serial_number = "WM20745001" Global $wm_component_status_id = "10" Global $wm_manufacturer ="Multi-Tech" Global $wm_model = "MTR-LAT1-B07" Global $cellular_carrier_id = "3" Global $iccid_esn = "89010303300012345678" Global $ip_address = "192.168.2.11" Global $NewIDNumber     Local $Curl = Curl_Easy_Init()     Local $Html = $Curl ; any number as identify     Local $Header = $Curl + 1 ; any number as identify     Local $HtmlFile = "cURL_Request.html"     Local $File = FileOpen($HtmlFile, 2 + 16)     Local $Slist = Curl_Slist_Append(0, "content-type: multipart/form-data; boundary=---011000010111000001101001")     $Slist = Curl_Slist_Append($Slist, "authorization: Token token=" & $Token)     Curl_Easy_Setopt($Curl, $CURLOPT_PROXY, "127.0.0.1") ; needed to use Charles web debugging proxy     Curl_Easy_Setopt($Curl, $CURLOPT_PROXYPORT, 8888) ; needed to use Charles     Curl_Easy_Setopt($Curl, $CURLOPT_HTTPHEADER, $Slist) ;     Curl_Easy_Setopt($Curl, $CURLOPT_URL, $Server & "wireless_module" & "s")     Curl_Easy_Setopt($Curl, $CURLOPT_SSL_VERIFYPEER, 0)     Curl_Easy_Setopt($Curl, $CURLOPT_TIMEOUT, 30)     Curl_Easy_Setopt($Curl, $CURLOPT_WRITEDATA, $Html)     Curl_Easy_Setopt($Curl, $CURLOPT_WRITEFUNCTION, Curl_FileWriteCallback())     Curl_Easy_Setopt($Curl, $CURLOPT_WRITEDATA, $File)     Local $HttpPost = ""     Local $LastItem = ""         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[serial_number]", $CURLFORM_COPYCONTENTS, $WM_serial_number, $CURLFORM_END)         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[component_status_id]", $CURLFORM_COPYCONTENTS, $wm_component_status_id, $CURLFORM_END)         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[manufacturer]", $CURLFORM_COPYCONTENTS, $wm_manufacturer, $CURLFORM_END)         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[model]", $CURLFORM_COPYCONTENTS, $wm_model, $CURLFORM_END)         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[cellular_carrier_id]", $CURLFORM_COPYCONTENTS, $cellular_carrier_id, $CURLFORM_END)         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[iccid_esn]", $CURLFORM_COPYCONTENTS, $iccid_esn, $CURLFORM_END)         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[ip_address]", $CURLFORM_COPYCONTENTS, $ip_address, $CURLFORM_END)         ; submit         Curl_Easy_Setopt($Curl, $CURLOPT_HTTPPOST, $HttpPost)         Local $Code = Curl_Easy_Perform($Curl)         If $Code = $CURLE_OK Then         ConsoleWrite("Content Type: " & Curl_Easy_GetInfo($Curl, $CURLINFO_CONTENT_TYPE) & @LF)         ConsoleWrite("Download Size: " & Curl_Easy_GetInfo($Curl, $CURLINFO_SIZE_DOWNLOAD) & @LF)         MsgBox(0, 'Html', BinaryToString(Curl_Data_Get($Html))) ; this is something I threw in for debugging, expecting to see SOMETHING. Returns nothing         MsgBox(0, 'Header', BinaryToString(Curl_Data_Get($Header))) ; this is something I threw in for debugging, expecting to see SOMETHING. Returns nothing         Local $response = Curl_Easy_GetInfo($Curl, $CURLINFO_RESPONSE_CODE)             If $response = "409" Then $response = "Failed due to a conflict."             If $response = "200" Then $response = "Was NOT created."             If $response = "201" Then $response = "Was created."             ; read the ID that was assigned and store it         $NewIDNumber = StringRight(StringLeft(BinaryToString(Curl_Data_Get($Html)), 10), 4) ; this DID work, but now it doesn't. An old compiled version still works ;~         Global $JsonObject = json_decode($Html); another debugging attempt. Did not use json functions previously and the program worked without it. ;~         Global $NewIDNumber = json_get($JsonObject, '.id')         ConsoleWrite(@CRLF &'! id:' & $NewIDNumber & @CRLF & @CRLF)    ; debugging feedback         MsgBox(0, $response, $wm_serial_number & " new ID = " & $NewIDNumber); debugging feedback         If $Code <> $CURLE_OK Then ConsoleWrite(Curl_Easy_StrError($Code) & @LF)             Local $Data = BinaryToString(Curl_Data_Get($Curl))             Curl_Easy_Cleanup($Curl)             Curl_Data_Cleanup($Curl)             Curl_Data_Cleanup($Header)             Curl_Data_Cleanup($Html)             Curl_FormFree($HttpPost)             Curl_slist_free_all($Slist)             curl_easy_reset($Curl)             FileClose($File)             ConsoleWrite(@LF)         EndIf  This is the captured request (minus the host and token)
      POST /api/v2/wireless_modules HTTP/1.1 Host: api. Accept: */* authorization: Token token= Content-Length: 942 Expect: 100-continue content-type: multipart/form-data; boundary=---011000010111000001101001; boundary=------------------------9adb0d87c7ea5061 --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[serial_number]" WM20745001 --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[component_status_id]" 10 --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[manufacturer]" Multi-Tech --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[model]" MTR-LAT1-B07 --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[cellular_carrier_id]" 3 --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[iccid_esn]" 89010303300012345678 --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[ip_address]" 192.168.2.11 --------------------------9adb0d87c7ea5061-- and the captured response
      HTTP/1.1 201 Created Date: Sun, 04 Apr 2021 00:12:18 GMT Server: Apache Cache-Control: max-age=0, private, must-revalidate Access-Control-Allow-Origin: not-allowed Vary: Accept-Encoding Access-Control-Max-Age: 1728000 X-XSS-Protection: 1; mode=block X-Request-Id: 71cfcf36-6020-48a6-a822-d2b393a27b69 Access-Control-Allow-Credentials: true Access-Control-Allow-Methods: PUT, OPTIONS, GET, POST ETag: W/"25d97fe8a9387cb4b9029a9e62b0bfa2" X-Frame-Options: SAMEORIGIN, SAMEORIGIN X-Runtime: 0.344005 X-Content-Type-Options: nosniff Access-Control-Request-Method: * X-Powered-By: Phusion Passenger 5.2.1 Strict-Transport-Security: max-age=63072000; includeSubDomains; preload Location: /wireless_modules/3195 Status: 201 Created Connection: close Transfer-Encoding: chunked Content-Type: application/json; charset=utf-8 X-Charles-Received-Continue: HTTP/1.1 100 Continue {"id":3195,"model":"MTR-LAT1-B07","serial_number":"WM20745001","manufacturer":"Multi-Tech","mfg_date":null,"iccid_esn":"89010303300012345678","ip_address":"192.168.2.11","purchase_order":null,"supplier":null,"cellular_carrier_id":3,"component_status_id":10,"component_status":{"id":10,"name":"Hold","description":"Available- Held for specific use"},"custom_attributes":[{"name":"Deactivated","type":"Boolean","value":false},{"name":"Port 3001","type":"Boolean","value":false}],"comments":[]}  
      Also attached is the log file. I need to read the id value. Clearly, it is arriving back to cURL, since it is being written out to the log, but I cannot seem to get to it within the code. 
      It is established that I may be an idiot, but this idiot has wasted days in non-billable hours trying to figure out what should be a simple glitch.
      Help???
       
      cURL_Request.html
    • By Colduction
      Hi AutoIt Members and Programmers, i have a problem with Telegram UDF that does not work on some of my servers, Telegram is not restricted in these machines, here is console output in Windows 7 (Server):
      >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\.NetFramework\Desktop\telegram-udf-autoit-master\tests\Test.au3" /UserParams +>20:20:40 Starting AutoIt3Wrapper (19.1127.1402.0} from:SciTE.exe (4.2.0.0) Keyboard:00000429 OS:WIN_7/Service Pack 1 CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\.NetFramework\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\.NetFramework\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.14.5) from:C:\Program Files (x86)\AutoIt3 input:C:\Users\.NetFramework\Desktop\telegram-udf-autoit-master\tests\Test.au3 +>20:20:40 AU3Check ended.rc:0 >Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\.NetFramework\Desktop\telegram-udf-autoit-master\tests\Test.au3" +>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop. Test file for Telegram UDF (https://github.com/xLinkOut/telegram-udf-autoit). This file need a valid ChatID of a Telegram user who has already sent at least a message to the bot, and a valid token given by @BotFather. Insert this data in the source code. "C:\Users\.NetFramework\Desktop\telegram-udf-autoit-master\src\Telegram.au3" (1098) : ==> The requested action with this object has failed.: $oHTTP.Send() $oHTTP^ ERROR ->20:20:41 AutoIt3.exe ended.rc:1 +>20:20:41 AutoIt3Wrapper Finished. >Exit code: 1 Time: 1.56 It's really annoying problem in WinHTTP
    • By nacerbaaziz
      goodmorning autoit team
      today am comming with some winhttp problems, i hope that you can help me to solve them.
      the first problem
      is when opening a request
      my forums api allow me to delete any post using the api key
      all functions work, i mean post / get
      but when i tried to use the delete verb it's gave me an html 404 error
      here is what am tried
      #include "WinHttp.au3" ; Open needed handles Global $hOpen = _WinHttpOpen() Global $hConnect = _WinHttpConnect($hOpen, "xxxxxxxx.com") ; Specify the reguest: Global $hRequest = _WinHttpOpenRequest($hConnect, "Delete", "/vb/Api/posts/10447/?hard_delete=true", default, default) _WinHttpAddRequestHeaders($hRequest, "XF-Api-Key:xxxxx") _WinHttpAddRequestHeaders($hRequest, "XF-Api-User:xxxxx") ; Send request _WinHttpSendRequest($hRequest) ; Wait for the response _WinHttpReceiveResponse($hRequest) Global $sHeader = 0, $sReturned = 0 ; If there is data available... If _WinHttpQueryDataAvailable($hRequest) Then $sHeader = _WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_CONTENT_DISPOSITION) ;Or maybe: ; $sHeader = _WinHttpQueryHeaders($hRequest, BitOR($WINHTTP_QUERY_RAW_HEADERS_CRLF, $WINHTTP_QUERY_CUSTOM), "Content-Disposition") Do $sReturned &= _WinHttpReadData($hRequest) Until @error msgBox(64, "", $sReturned) endIf ; Close handles _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen)  
      and here is the error message
      <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>403 Forbidden</title> </head><body> <h1>Forbidden</h1> <p>You don't have permission to access /vb/Api/posts/10447/ on this server.<br /> </p> </body></html>  
      i hope you can help me 
      thanks in advance
×
×
  • Create New...