Jump to content

Recommended Posts

  • Replies 953
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

The other day mikeytown2 posted one post in HTTP UDF's thread that got me thinking if there is better (different) method to send requests through the HTTP protocol to HTTP servers. There is Winhttp.d

Yes thanks. But the only valid warning is with unreferenced parameter inside __WinHttpFormUpload. I'll fix that.

Hey Raizeno, try this: #include "WinHttp.au3" $sAddress = "https://api.pushover.net/1/messages.json" $sApiToken = "av26ac2nAXLyPKg2QMy4zf9YcUjz2G" ; <-yours here $sUserKey = "uMQf396GvMgrsDr

Posted Images

I did make a test account and verified that the code works before posting it here. Are your credentials ok? What's returned as $sRead, both before the confirmation page and after?

No, my account is maintained, so there are unlikely to be the problem, my $sRead is contain error page

Do you execute all of my code, here is my full source, maybe my code is wrong, I hope you can examine my code, basically what i want to do is, I need to download file that the link is dynamic, i don't know the link before I open the page, so I write a code to login the website, then open the page contain the link, then open the link generated by the page,

open > connect > login > disconnect > connect > get link > disconnect > connect > download > disconnect > close

Local $sReportLink = "https://go.xero.com/Bank/BankTransactions.aspx?accountID=9E6416D4-90EA-4E23-BDA5-35BB37871AE1"
Func _DownloadReport($sReportLink, $sTitle, ByRef $sFilePath)

    ; get username and password
    Local $sUserName = IniRead($sAccFile, "data", "u", "")
    Local $sPassword = IniRead($sAccFile, "data", "p", "")

    ; initialize and get session handle
    Local $hOpen = _WinHttpOpen()
    ; get connection handle
    Local $hConnect = _WinHttpConnect($hOpen, "https://login.xero.com")

    ; fill login form:
    Local $sRead = _WinHttpSimpleFormFill($hConnect, _
                    Default, _ ; location of the form
                    "LoginForm", _ ; id of the form
                    "name:userName", $sUserName, _
                    "name:password", $sPassword)

    While StringInStr($sRead, "<title>Working...</title>") Then
        $sRead = _WinHttpSimpleFormFill($hConnect)
    WEnd
    
    ; this display error page
_____________________________________________________________
    ShowWinHttpResult($sRead)
    MsgBox(0, 0, "Delay 1")

    ; check both @error and inspect $sRead to see if login was good
    If @error Then
        MsgBox(262144 + 8192 + 256 + 16, "Error: 1756", "Script can not open connection to xero, script will skip this bank.")
        _WinHttpCloseHandle($hConnect)
        _WinHttpCloseHandle($hOpen)
        Return False
    EndIf

    ; Close connection handle
    _WinHttpCloseHandle($hConnect)

    ; Open new connection handle to get report and statementDBId
    Local $hConnect = _WinHttpConnect($hOpen, "https://go.xero.com")
    Local $sHtml = _WinHttpSimpleSSLRequest($hConnect, Default, $sReportLink, Default, Default, Default, Default, 0)

    ShowWinHttpResult($sHtml)
    MsgBox(0, 0, "Delay")

    ; Close connection handle
    _WinHttpCloseHandle($hConnect)

    ; Get report and statementDBId
    Local $reportId, $statementDBId
    _GetReportID($reportId, $statementDBId, $sHtml)

    If $reportId = "" Or $statementDBId = "" Then
        MsgBox(262144 + 8192 + 256 + 16, "Error: 1777", "Script can not get reportId or statementDBId value, script will skip this bank.")
        _WinHttpCloseHandle($hOpen)
        Return False
    EndIf

    Local $sFileLink = "Reports/ExcelReport.aspx?reportId=" & $reportId & "&report=&statement=" & $statementDBId & "&attPage="

    ; Open new connection handle to download report
    Local $hConnect = _WinHttpConnect($hOpen, "https://go.xero.com")
    Local $hXls = _WinHttpSimpleSSLRequest($hConnect, Default, $sFileLink, Default, Default, Default, True, 2)

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

    ; get provided filename from http header
    Local $aArray = StringRegExp($hXls[0], '(?<=filename=")(.*)(?=.xls")', 1)
    ; check if filename returned
    If Not IsArray($aArray) Then
        MsgBox(262144 + 8192 + 256 + 16, "Error: 1797", "Script can not download the report, script will skip this bank.")
        Return False
    EndIf
    ; define filename and directory
    Local $aFileName = StringSplit($aArray[0], "[")
    $sFilePath = $sDataDir & "\" & StringTrimRight($aFileName[1], 22)
    If Not FileExists($sFilePath) Then DirCreate($sFilePath)

    ; generate new filename and path
    Local $sFileName = $sFilePath & "\" & $sTitle & " - Bank Reconcilliation"
    If FileExists($sFileName & ".xls") Then
        Local $n = 0
        Do
            $n += 1
        Until FileExists($sFileName & "(" & $n & ").xls") = False
        $sFileName = $sFileName & "(" & $n & ")"
    EndIf

    ; save file
    Local $hFile = FileOpen($sFileName & ".xls", 18)
    FileWrite($hFile, $hXls[1])
    FileClose($hFile)

    ProcessClose($SplashPID)

    Return $sFileName & ".xls"
EndFunc

and here is the page returned on the first WinHttpSimpleFormFill

<!DOCTYPE html>

<html>
<head>
    <title>MyXero | Error 404: Page Not Found</title>
    <link rel="stylesheet" href="/content/all/page/error/error-26e68d8e747b7cc0d0b7d39eae325c03.css" type="text/css" />
</head>
<body>
    <div class="header">
        <div class="content">
            <div class="logo">Xero</div>
        </div>
    </div>
    <div class="body">
        <div class="content">

            <h1>We're sorry, a problem has occurred.
            </h1>
            <p>
                <b>Please try again
                </b>
                <br />
                It's possible the problem you have encountered is temporary. Please either click the back button or <a href="javascript:" onclick="history.back(-1)">click this link</a> to return to the previous screen and try again.
            </p>

            <p>
                <b>We're on it
                </b>
                <br />
                If this is a problem you've encountered before, it's likely we're already fixing it. We keep a record of every error that occurs and regularly review and set about fixing them so they don't happen again.
            </p>

            <p>
                <b>Contact Support
                </b>
                <br />
                If the problem persists or is urgent please do let us know by emailing <a href="mailto:support@xero.com">support@xero.com</a> or by navigating back to a screen in Xero where there is a link to Contact Support directly from the Help menu.
            </p>

            <p>
                When you contact us, please include as much detail about your problem as possible. Including details such as the specific steps which lead up to the problem and the name of the organisation will help us identify the problem and resolve it. Thank you.
            </p>
        </div>
    </div>
    <div class="footer">
        <div class="content">
            <a href="http://www.xero.com/signup/"><b>Sign up for free</b></a> if you don't have a Xero login.
                <div>
                    <a href="http://www.xero.com/about/privacy/">Privacy Policy</a> | <a href="http://www.xero.com/about/terms/">Terms of Use</a>
                </div>
        </div>
    </div>
</body>
</html>

 

Edited by ngskicker
Link to post
Share on other sites

Are you sure that's the page returned by the first _WinHttpSimpleFormFill?

That looks like the output of this part of your code:

; Open new connection handle to get report and statementDBId
Local $hConnect = _WinHttpConnect($hOpen, "https://go.xero.com")
Local $sHtml = _WinHttpSimpleSSLRequest($hConnect, Default, $sReportLink, Default, Default, Default, Default, 0

Anyway report link is:

Local $sReportLink = "Bank/BankTransactions.aspx?accountID=9E6416D4-90EA-4E23-BDA5-35BB37871AE1"

... and not what you use.

 

Do you use SciTE or any other editor that can print console output?

♡♡♡

.

eMyvnE

Link to post
Share on other sites

So break it into chunks and send them like that.

You need to be more precise about what you want to do to get better reply.

I'm agree with you.

Now I'm using following function (extracted from your help file):

Func PUT_HTTP ($IP,$URI,$sPostData)
    ; Initialize and get session handle
Local $hOpen = _WinHttpOpen()
; Get connection handle
Local $hConnect = _WinHttpConnect($hOpen, "http://"&$IP)
; Specify the reguest
Local $hRequest = _WinHttpOpenRequest($hConnect, "PUT", $URI)

; Send request
_WinHttpSendRequest($hRequest, Default, Default, StringLen($sPostData))

; Write additional data to send
_WinHttpWriteData($hRequest, $sPostData)

; Wait for the response
_WinHttpReceiveResponse($hRequest)

; Check if there is data available...
If _WinHttpQueryDataAvailable($hRequest) Then
    ConsoleWrite(_WinHttpReadData($hRequest)&@CRLF)
EndIf

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



EndFunc

But the problem is that I don't know what I need to modify in the function above in order to send the $sPostData variable as a chunks of 1460bytes length.

Is _WinHttpSendRequest the function which sends the headers and _WinHttpWriteData the function that I need to use to send the data as a chunks?

 

Link to post
Share on other sites

I'm agree with you.

Now I'm using following function (extracted from your help file):

Func PUT_HTTP ($IP,$URI,$sPostData)
    ; Initialize and get session handle
Local $hOpen = _WinHttpOpen()
; Get connection handle
Local $hConnect = _WinHttpConnect($hOpen, "http://"&$IP)
; Specify the reguest
Local $hRequest = _WinHttpOpenRequest($hConnect, "PUT", $URI)

; Send request
_WinHttpSendRequest($hRequest, Default, Default, StringLen($sPostData))

; Write additional data to send
_WinHttpWriteData($hRequest, $sPostData)

; Wait for the response
_WinHttpReceiveResponse($hRequest)

; Check if there is data available...
If _WinHttpQueryDataAvailable($hRequest) Then
    ConsoleWrite(_WinHttpReadData($hRequest)&@CRLF)
EndIf

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



EndFunc

But the problem is that I don't know what I need to modify in the function above in order to send the $sPostData variable as a chunks of 1460bytes length.

Is _WinHttpSendRequest the function which sends the headers and _WinHttpWriteData the function that I need to use to send the data as a chunks?

 

For example you could modify that code to send one character at time:

;...

; Send request
_WinHttpSendRequest($hRequest, Default, Default, StringLen($sPostData))

For $i = 1 To StringLen($sPostData)
    ; Write additional data one character (byte) at time
    _WinHttpWriteData($hRequest, StringMid($sPostData, $i, 1))
Next

;...

 

♡♡♡

.

eMyvnE

Link to post
Share on other sites

 I use scite

I'm sure the error from the first _WinHttpSimpleFormFill, because I write a fuction to save the return to a file, but even though the result is error page, it seems I am successfully login to the website, because the second request, _WinHttpSimpleSSLRequest, return a "working page", and if I open the page in my browser the page redirect to the right report page that I want, but if I place your while loop code "While StringInStr($sRead, "<title>Working...</title>")" what I got is error page,

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

Hey Guys,

Just in case anyone stumbles upon this in the future, there is a much easier way to call the winhttp API. use the following code below

$http = ObjCreate("winhttp.winhttprequest.5.1")
$http.Open("GET", "http://yourlink.com", False)
$http.Send()
$HTMLText = $http.ResponseText

hope this helps, if you want more info on winhttp and its commands use this https://msdn.microsoft.com/en-us/library/windows/desktop/aa384106.aspx for reference to other commands on winhttp.

Link to post
Share on other sites
  • 2 months later...

I have troubles with connection to some (not all) https sites

I'm getting _WinHttpSendRequest @error = 1 and ignoring ssl errors wont help. My RSS agregator also cannot read those feeds, while Firefox do not have any problems...

Is there a way to increase ignorance to SSL errors ? :sweating:  Or any other reason for SSL connection to fail?

 

Func _UpdateRSSFeed($sFeedURL)

    Local $aURL, $sRSSSiteURL, $sRSSSitePage, $hOpen, $hConnect, $hRequest, $iResponce, $sResponce = "", $sHeaders
    $aURL = StringRegExp($sFeedURL,'^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?',3)
    $sRSSSiteURL = $aURL[0] & $aURL[2]
    $sRSSSitePage = $aURL[4] & ((UBound($aURL) > 5)?($aURL[5]):(""))

    ConsoleWrite("$sFeedURL = " & $sFeedURL & @CRLF)
    ConsoleWrite("$sRSSSiteURL = " & $sRSSSiteURL & @CRLF)
    ConsoleWrite("$sRSSSitePage = " & $sRSSSitePage & @CRLF)

    $hOpen = _WinHttpOpen()
    _WinHttpSetStatusCallback($hOpen, $hWINHTTP_STATUS_CALLBACK)

    Switch $aURL[1]
        Case "http"
            $hConnect = _WinHttpConnect($hOpen, $sRSSSiteURL)
            $hRequest = _WinHttpOpenRequest($hConnect, "GET", $sRSSSitePage)
        Case "https"
            $hConnect = _WinHttpConnect($hOpen, $sRSSSiteURL, $INTERNET_DEFAULT_HTTPS_PORT)
            $hRequest = _WinHttpOpenRequest($hConnect, "GET", $sRSSSitePage, Default, Default, Default, $WINHTTP_FLAG_SECURE)
            _WinHttpSetOption($hRequest, $WINHTTP_OPTION_SECURITY_FLAGS, BitOR($SECURITY_FLAG_IGNORE_CERT_DATE_INVALID, $SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE, $SECURITY_FLAG_IGNORE_UNKNOWN_CA, $SECURITY_FLAG_IGNORE_CERT_CN_INVALID))
    EndSwitch

    _WinHttpAddRequestHeaders($hConnect, "User-Agent: Mozilla/5.0 (Windows NT 5.2; WOW64; rv:10.0.11) Gecko/20100101 Firefox/10.0.11")
    _WinHttpAddRequestHeaders($hConnect, "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
    ;_WinHttpAddRequestHeaders($hConnect, "Accept-Language: en-US,en;q=0.5")
    _WinHttpAddRequestHeaders($hConnect, "Accept-Encoding: gzip, deflate")
    _WinHttpAddRequestHeaders($hConnect, Get_IfModifiedSinceHeader())
    ;_WinHttpAddRequestHeaders($hConnect, "Referer: " & $sRSSSiteURL)
    _WinHttpAddRequestHeaders($hConnect, "Connection: keep-alive" & @CRLF)

    _WinHttpSendRequest($hRequest)
    ConsoleWrite("_WinHttpSendRequest @error = " & @error & @CRLF)

    $iResponce = _WinHttpReceiveResponse($hRequest)
    If $iResponce = 1 Then
        $sHeaders = _WinHttpQueryHeaders($hRequest)
        ConsoleWrite("$sHeaders = " & $sHeaders & @CRLF)
        If StringInStr($sHeaders, "304") Then
            $sResponce = "Not Modified"
        Else
            While 1
                $sPart = _WinHttpReadData($hRequest,1)
                If @error Then ExitLoop
                $sResponce &= $sPart
                Sleep(33)
            WEnd
        EndIf
    EndIf
    _WinHttpCloseHandle($hRequest)
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)

    Return $sResponce
EndFunc
;------------------------------------------------------------------------------------------
Func Get_IfModifiedSinceHeader()
    Local $tTime, $sTime
    $tTime = _Date_Time_GetSystemTime()
    $tTime = _Date_Time_SystemTimeToDateTimeStr($tTime, 1)
    $tTime = _DateAdd( "h", -2, $tTime)
    $sTime = Execute(StringRegExpReplace($tTime, "((\d+)\D(\d+)\D(\d+)\D(\d+\:\d+\:\d+))", "_DateDayOfWeek(_DateToDayOfWeek($2,$3,$4), 1) & ', ' & $4 & ' ' & _DateToMonth($3, $DMW_SHORTNAME) & ' $2 $5 GMT'"))
    Return "If-Modified-Since: " & $sTime
EndFunc
;------------------------------------------------------------------------------------------

 

!->Current status of the connection: 1024    An HINTERNET handle has been created.
!->Current status of the connection: 1024    An HINTERNET handle has been created.
!->Current status of the connection: 1   Looking up the IP address of a server name.
!->Current status of the connection: 2   Successfully found the IP address of the server.
!->Current status of the connection: 4   Connecting to the server.
!->Current status of the connection: 8   Successfully connected to the server.
!->Current status of the connection: 256     Closing the connection to the server
!->Current status of the connection: 512     Successfully closed the connection to the server.
_WinHttpSendRequest @error = 1
!->Current status of the connection: 2048    This handle value has been terminated.
!->Current status of the connection: 2048    This handle value has been terminated.
!->Current status of the connection: 2048    This handle value has been terminated.

 

Link to post
Share on other sites

Which one?

Btw, _WinHttpAddRequestHeaders asks for request handle, not connection. Also, this line:

_WinHttpAddRequestHeaders(..., "Accept-Encoding: gzip, deflate")

... makes no sense if there's no code to decompress the data if the server decides to serve it compressed.

Edited by trancexx

♡♡♡

.

eMyvnE

Link to post
Share on other sites

Thanks!

if i try this forum feed : $sFeedURL = "https://www.autoitscript.com/forum/forum/9-autoit-example-scripts.xml"

i get this output:

!->Current status of the connection: 1024    An HINTERNET handle has been created.
!->Current status of the connection: 1024    An HINTERNET handle has been created.
!->Current status of the connection: 1   Looking up the IP address of a server name.
!->Current status of the connection: 2   Successfully found the IP address of the server.
!->Current status of the connection: 4   Connecting to the server.
!->Current status of the connection: 8   Successfully connected to the server.
!->Current status of the connection: 65536   One or more errors were encountered while retrieving a Secure Sockets Layer (SSL) certificate from the server.
!->Current status of the connection: 256     Closing the connection to the server
!->Current status of the connection: 512     Successfully closed the connection to the server.
_WinHttpSendRequest @error = 1
!->Current status of the connection: 2048    This handle value has been terminated.
!->Current status of the connection: 2048    This handle value has been terminated.
!->Current status of the connection: 2048    This handle value has been terminated.

Why? Isnt SSL errors should be ignored after:

_WinHttpSetOption($hRequest, $WINHTTP_OPTION_SECURITY_FLAGS, BitOR($SECURITY_FLAG_IGNORE_CERT_DATE_INVALID, $SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE, $SECURITY_FLAG_IGNORE_UNKNOWN_CA, $SECURITY_FLAG_IGNORE_CERT_CN_INVALID))

 

Quote

... makes no sense if there's no code to decompress the data if the server decides to serve it compressed.

I'm working on it  ;)

Quote

Which one?

it's slightly sensitive... i'm searching feeds with same output in console

Link to post
Share on other sites

I want to upload an image inside a notification with pushbullet.

After contacting the server, it answers some keys needed to upload the pic with multipart/form-data. In their API they give this example with CURL:   https://docs.pushbullet.com/v9/#upload-request

 

Quote

Copy of all the parameters from the data object in the response to the upload request. In addition to that, the file should be uploaded as the parameter file. This request is more complicated than most of the other API requests and requires multipart/form-data encoding.

After the request completes, the file will be available at file_url from the upload request response.

curl -i -X POST https://s3.amazonaws.com/pushbullet-uploads \
  -F awsaccesskeyid=AKIAJJIUQPUDGPM4GD3W \
  -F acl=public-read \
  -F key=ubd-CWb1dP5XrZzvHReWHCycIwPyuAMp2R9I/image.png \
  -F signature=UX5s1uIy1ov6+xlj58JY7rGFKcs= \
  -F policy=eyKjb25kaXRpb25z6MzcuMjM0MTMwWiJ9 \
  -F content-type=image/png
  -F file=@test.txt

So, I tried:

local $hOpen = _WinHttpOpen()
            
    local $hConnect = _WinHttpConnect($hOpen, "https://s3.amazonaws.com/pushbullet-uploads")
    
    ; Json data are from the previous server answer:
    local $sHTM = _WinHttpSimpleFormFill($hConnect, Default, "name:awsaccesskeyid", _JSONGet($json, "data.awsaccesskeyid"), "name:acl", _JSONGet($json, "data.acl"), "name:key", _JSONGet($json, "data.key"), "name:signature", _JSONGet($json, "data.signature"), "name:policy", _JSONGet($json, "data.policy"), "name:file" , "E:\myfile.jpg")
            
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)

    ConsoleWrite(">Server response:" & @CRLF & $sHTM & @CRLF)

But I get no Server answer. And @error=1 , no Form found.
 

 

Edited by frank10
Link to post
Share on other sites

So, pushbullet uploads the file to the S3 amazon servers. Their Form data is like this:

http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPOST.html

I tried to construct the form and send it with _WinHttpSendRequest multipart/form-data, as _WinHttpSimpleFormFill doesn't work:

Local $hFile = FileOpen($sPath & $fileName, 16)
local $FileData = FileRead($hFile)

local $sBoundary = "-----------" & _TimeToTicks(@HOUR, @MIN, @SEC)

Local $postData ='' 
$postData &= 'Content-Disposition: form-data; name="awsaccesskeyid"' & @CRLF  & @CRLF & $awsaccesskeyid & @CRLF
$postData &=  $sBoundary & @CRLF
$postData &= 'Content-Disposition: form-data; name="acl"' & @CRLF & @CRLF & $acl & @CRLF
$postData &=  $sBoundary & @CRLF
$postData &= 'Content-Disposition: form-data; name="key"' & @CRLF & @CRLF & $key & @CRLF
$postData &=  $sBoundary & @CRLF
$postData &= 'Content-Disposition: form-data; name="signature"' & @CRLF & @CRLF & $signature & @CRLF
$postData &=  $sBoundary & @CRLF
$postData &= 'Content-Disposition: form-data; name="policy"' & @CRLF & @CRLF & $policy & @CRLF
$postData &=  $sBoundary & @CRLF
$postData &= 'Content-Disposition: form-data; name="file"; filename="' & $fileName & '"' & @CRLF
$postData &= "Content-Type: " & $fileType & @CRLF & @CRLF

$postData &=  $FileData & @CRLF
$postData &=  $sBoundary

local $hOpen = _WinHttpOpen()
local $hConnect = _WinHttpConnect($hOpen, "https://s3.amazonaws.com")
local $hRequest = _WinHttpOpenRequest($hConnect, "POST", "pushbullet-uploads", -1, -1, -1, $WINHTTP_FLAG_SECURE) 

local $hSendRequest = _WinHttpSendRequest($hRequest, "Content-Type: multipart/form-data; boundary=" & $sBoundary, $postData, StringLen($postData))

ConsoleWrite(">Server Err:" & @error & "__" & @extended & @CRLF)
_WinHttpReceiveResponse($hRequest)

local $sHeader = _WinHttpQueryHeaders($hRequest)
ConsoleWrite("FullHeader:" & $sHeader & @CRLF)
; See what's returned
local $sReturned
If _WinHttpQueryDataAvailable($hRequest) Then ; if there is data
  Do
      $sReturned &= _WinHttpReadData($hRequest)
  Until @error
EndIf
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
ConsoleWrite("Returned:" & $sReturned & @CRLF)

FileClose($hFile)

My postData looks like:

Content-Disposition: form-data; name="awsaccesskeyid"

AKIAJJIxxxxxxx4GD3W
-----------62147000
Content-Disposition: form-data; name="acl"

public-read
-----------62147000
Content-Disposition: form-data; name="key"

3z6AZ65IxxxxxxxxlElTzDvP/ImmagineSmall.jpg
-----------62147000
Content-Disposition: form-data; name="signature"

UX5s1xxxxxxxY7rGFKcs=
-----------62147000
Content-Disposition: form-data; name="policy"

eyKjb25xxxxxxxx0MTMwWiJ9
-----------62147000
Content-Disposition: form-data; name="file"; filename="ImmagineSmall.jpg"
Content-Type: image/jpg

.......and here goes the binary data of the file.....
-----------62147000

 

BUT I get _WinHttpSendRequest  @error = 0 and amazon's server gives me ERR:

HTTP/1.1 400 Bad Request
Connection: close
Date: Sat, 27 Feb 2016 16:29:24 GMT
Transfer-Encoding: chunked
Content-Type: application/xml
Server: AmazonS3
x-amz-request-id: A06D2Cxxxxxxxxxxxxxx0FA
x-amz-id-2: zf0xxl8BxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxgOswgsbAn3cA/o=

<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>InvalidArgument</Code><Message>POST requires exactly one file upload per request.</Message><ArgumentName>file</ArgumentName><ArgumentValue>0</ArgumentValue><RequestId>6035A5xxxxxxxxD92</RequestId><HostId>XiOQp4FI1JxxxxxxxxxxxxxxxxxxxxxxxxxI4w6uz0c=</HostId></Error>
HeadRes>Connection: close
Date: Sat, 27 Feb 2016 16:29:23 GMT
Transfer-Encoding: chunked
Content-Type: application/xml
Server: AmazonS3
x-amz-request-id: 6035xxxxxxD92
x-amz-id-2: XiOQp4FI1JhVxxxxxxxxxxxxx6YCI4w6uz0c=

"POST requires exactly one file upload " ?? I 've uploaded one file only...

I searched some similar ERR but I found only one "solution" I've not understood:

http://stackoverflow.com/questions/6030371/http-post-with-httpwebrequest

What's that "--" thingy to add to the boundary??

EDIT: it seems winHttp UDF adds it automatically (before and after at the end), isn't it?

EDIT2:but only in simpleformfill...

Any idea to solve the problem?

Edited by frank10
Link to post
Share on other sites

I tried this:

local $sAddress = "https://s3.amazonaws.com/pushbullet-uploads"
        local $sFileToUpload = $sPath & $fileName 
        local $sForm = _
            '<form action="' & $sAddress & '" method="post" enctype="multipart/form-data">' & _
            ' <input type="text" name="awsaccesskeyid"/>' & _ ;
            ' <input type="text" name="acl"/>' & _ ;
            ' <input type="text" name="key"/>' & _ ;
            ' <input type="text" name="signature"/>' & _ ;
            ' <input type="text" name="policy"/>' & _ ;
            ' <input type="file" name="file"/>' & _ ;
            '</form>'

        local $hOpen = _WinHttpOpen()
        local $hConnect = $sForm 
        local $sHTML = _WinHttpSimpleFormFill($hConnect, $hOpen, _
            Default, _
            "name:awsaccesskeyid", $awsaccesskeyid , _
            "name:acl", $acl, _
            "name:key", $key, _
            "name:signature", $signature, _
            "name:policy", $policy, _
            "name:file", $sFileToUpload)

        If @error Then
          MsgBox(4096, "Error", "Error number = " & @error)
        Else
          ConsoleWrite($sHTML & @CRLF)
        EndIf

        _WinHttpCloseHandle($hConnect)
        _WinHttpCloseHandle($hOpen)

but it gives me this ERR:

<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>InvalidAccessKeyId</Code><Message>The AWS Access Key Id you provided does not exist in our records.</Message><AWSAccessKeyId>AKIAJJxxxxxxx4GD3W</AWSAccessKeyId><RequestId>64592xxxxxEF0</RequestId><HostId>XGSW3AWgeWxxxxxxxxxxxxxxREUiF8</HostId></Error>

But the rest of the code was unchanged, so the var $awsaccesskeyid is the correct requested var.

And the <AWSAccessKeyId>AKIAJJIxxxxxGD3W</AWSAccessKeyId> is exactly the correct value... Maybe there are problems in composing the POST form??

 

Once solved this one, it could be another problem in the fact they want in the form name=file another parameter: filename="name.jpg" before sending the binary. How can I put it in the same form input?

Edit:

Maybe:

'<input type="file" name="file" filename="' & $fileName & '"/>'

EDIT2:

I looked at SimpleForm in UDF and I see you already put filename="....." so that part is already ok.

Edited by frank10
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.

×
×
  • Create New...