B4J Question Curl formating

atiaust

Active Member
Licensed User
Longtime User
Hi All,
I am trying to format the following curl request.

curl -X POST https://node02.myqtthub.com/login 56 -d ‘{“clientId” : “YourAdminClientId”, “userName” : “YourUsername”, “password” : “aPassword”, “cleanSession” : false }’

I have tried to follow Erel's examples without success.

Below is the resulting error:

Code:
Waiting for debugger to connect...

ResponseError. Reason: Bad Request, Response: <!DOCTYPE html>
<html lang="en">
    <head>
        <title>Bad Request</title>
        <style>
            html, body, pre {
                margin: 0;
                padding: 0;
                font-family: Monaco, 'Lucida Console', monospace;
                background: #ECECEC;
            }
            h1 {
                margin: 0;
                background: #AD632A;
                padding: 20px 45px;
                color: #fff;
                text-shadow: 1px 1px 1px rgba(0,0,0,.3);
                border-bottom: 1px solid #9F5805;
                font-size: 28px;
            }
            p#detail {
                margin: 0;
                padding: 15px 45px;
                background: #F6A960;
                border-top: 4px solid #D29052;
                color: #733512;
                text-shadow: 1px 1px 1px rgba(255,255,255,.3);
                font-size: 14px;
                border-bottom: 1px solid #BA7F5B;
            }
        </style>
    </head>
    <body>
        <h1>Bad Request</h1>
        <p id="detail">
            For request 'POST /login' [Invalid Json: Unexpected character (&#x27;:&#x27; (code 58)): was expecting comma to separate Array entries
 at [Source: akka.util.ByteIterator$ByteArrayIterator$$anon$1@39ab7c44; line: 1, column: 15]]
        </p>
    </body>
</html>
ugh

Any advise gratefully accepted.
 
Where is the code you were using?
 
Upvote 0
Sorry, forgot that bit of info.

B4X:
Sub curl   
    Dim stringtosend As String = $" ["clientID" : "myClientId", "userName" : "myUserName", "password" : "myPassword", "cleanSession" : false ]"$
    Dim j As HttpJob
    j.Initialize("", Me)
    Log("Initialising")
    Dim link As String = "https://node02.myqtthub.com/login"
    j.poststring(link,stringtosend )

    Wait For (j) JobDone(j As HttpJob)
    
    If j.Success=True Then
        Log(j.getstring)
        Log("success")
        j.Release
    Else
        'do something'
        Log("ugh")
        j.Release
    End If
    
End Sub
 
Upvote 0
curl -X POST https://node02.myqtthub.com/login 56 -d ‘{“clientId” : “YourAdminClientId”, “userName” : “YourUsername”, “password” : “aPassword”, “cleanSession” : false }’
Dim stringtosend As String = $" ["clientID" : "myClientId", "userName" : "myUserName", "password" : "myPassword", "cleanSession" : false ]"$

These two does not match!

The Original starts with a {; means, it contains a Map.
You are posting a [ at the beginning; means, you are sending a LIST

B4X:
dim str2send as string = $"{"clientId" : "YourAdminClientId", "userName" : "YourUsername", "password" : "aPassword", "cleanSession" : false }"$
 
Upvote 0
Following on from above.

The next part of my data request uses the tokenId from the returned string request (below) and uses the token as a cookie to get the data download.

Waiting for debugger to connect...
Program started.
Initialising
{"clientId":"clientID","validUntil":1599115643,"stamp":1598942843,"cleanSession":false,"tokenId":"d8933140-8fb2-4787-b96d-9d149000d656"}
success

The curl string for the data download API is:

curl --cookie ‘tokenId=e734b134-0f05-4405-935c-7a4834c0603c’ -X POST https://node02.myqtthub.com/stashed/download 3 -d ‘{“tokenId” : “e734b134-0f05-4405-935c-7a4834c0603c”, “domainName” : “your-hub-domain”, “stashName” : “your-stash-name”, “downloadAs” : “csv”, “downloadFrame” : “all”}’

My code I am trying to use is but I am not sure how to firstly send the "cookie" followed by the data request.

B4X:
   Dim stringtosend As String = $"{"tokenId" : ${token}, "domainName" : "mydomainName ", "stashName" : "myStash", "downloadAs" : "csv", "downloadFrame" : "all" }"$
    Log(stringtosend)
    Dim j As HttpJob
    j.Initialize("", Me)
    Log("Initialising")
    Dim link As String = "https://node02.myqtthub.com/stashed/download"
    j.poststring(link,stringtosend )
    
    Wait For (j) JobDone(j As HttpJob)
    
    If j.Success=True Then
        Log(j.getstring)
        Log("success")
        j.Release
    Else
        'do something'
        Log("ugh")
        j.Release
    End If

The above code gets an error to say that the cookie is expected.

Any ideas?

Thanks
 
Upvote 0
Back
Top