Why a curl command works but a similar .Q.hp command fails when sending alerts to TEAMS from KDB - kdb

I have this curl command to send alerts to TEAMS and it works fine:
system"curl -H 'Content-Type: application/json' -d '{\"text\" : \"Hello World\"}' https://<link to webhook>"
I wanted to use .Q.hp instead just to keep things in KDB and I constructed this one :
.Q.hp["https://<link to webhook>";.h.ty`json] .j.j enlist[`text]!enlist"Hello World"
and I get the following error :
"<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
</body></html>
"
Any ideas why the .Q.hp is not working?

Related

Print only one CURL response after redirects Powershell

How do I build a cURL command that will follow redirects, but only return the content from the final (200) response? For example, I run curl.exe -LIk securityheaders.com and it returns the 301 response headers and the 200 response headers. I want to assign a variable to that cURL and only have the regex from the 200 response headers to check against a set of conditions.
You are using -LIk that means:
-k, --insecure Allow insecure server connections (OK)
-L, --location Follow redirects (OK)
-I, --head Show document info only (WHY)
When you put -I you are request for the document info only when all you want to is the content, just remove -I.
curl -Lk securityheaders.com
<!DOCTYPE HTML>
<html lang="en">
...

How to fill this web form from the command line?

I want to fill a form on a webpage to send some files via the command line instead of using the browser. I found cURL could do that for me but I’m not sure how. Besides that, I found out the "authenticity_token" changes for every request. How would I successfully authenticate and post my files?
I stripped down the html code to present only the inputs, see below. Thanks for having a look.
<form action="https://XXXXXXXX.com/aspera/faspex/test/dropbox_submissions" class="well form-horizontal form-horizontal-small-labels" id="send" method="post"><div style="margin:0;padding:0;display:inline"><input name="authenticity_token" type="hidden" value="cU/zhZKnbjk90v57Phmdgewq97lKclj63MtzfCHhEqc=" /></div>
<input id="dropbox_id" name="dropbox[id]" type="hidden" value="738" />
<input id="passcode" name="passcode" type="hidden" value="1738d1bc02755019655dd424Xf2717f1c8a7c579" />
<input id="delivery_title" maxlength="100" name="delivery[title]" size="100" type="text" value="" />
<input id="fileupload" multiple="multiple" name="file" type="file" />
<input id="delivery_source_paths_list" name="delivery[source_paths_list]" type="hidden" />
<input class="btn large primary" data-prompt_password="true" disabled="disabled" id="send_button" name="commit" type="submit" value="Send Package" />
<label>Passphrase:</label>
<input autocomplete="off" id="password" type="password" />
<label>Confirmation:</label>
<input autocomplete="off" id="password_confirmation" type="password" />
</form>
This seems to be an IBM Aspera Faspex submission page.
In fact the actual file transfer will be done using IBM Aspera FASP protocol (free on client side).
You can use the following free client which will allow you to send to faspex, using either an authenticated access or a public access (with passcode in url):
https://www.rubydoc.info/gems/asperalm
example:
mlia faspex package send --link='https://faspex.org.com/aspera/faspex/external/dropbox_submissions/new?passcode=xxx123xxx.........' --delivery-info=#json:'{"title":"my title"}' /path/to/files
This looks like a CSRF defence.
You need to make two requests and use a cookie jar to store cookies between them.
The first request you'll need to run through an HTML parser (e.g. pup) to extract the authenticity_token.
Then you'll need to make a second request and use the data and cookie jar from the first.
You can open debugger in any browser (developer mode) to demonstrate a html form and capture network request and copy it as curl.
Destination host must exist though since you need some response from the POST action.
This is what I got from my chrome browser.
curl 'https://XXXXXXXX.com/aspera/faspex/test/dropbox_submissions' -X POST \
-H 'Connection: keep-alive' \
-H 'Cache-Control: max-age=0' -H 'Upgrade-Insecure-Requests: 1' -H 'Origin: null' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36' \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3' \
-H 'Accept-Encoding: gzip, deflate' \
-H 'Accept-Language: en-US,en;q=0.9,ko;q=0.8,la;q=0.7' \
--data 'authenticity_token=cU%2FzhZKnbjk90v57Phmdgewq97lKclj63MtzfCHhEqc%3D&dropbox%5Bid%5D=738&passcode=1738d1bc02755019655dd424Xf2717f1c8a7c579&delivery%5Btitle%5D=&file=&delivery%5Bsource_paths_list%5D=' --compressed --insecure

How to fix this error and what does this error mean in IBM Cloud?

Now I would like to use "Speech to Text" on IBM Cloud to get Japanese text from Speech data, mp3.
However, I have gotten the same error as below after I tried it many times.
<HTML><HEAD>
<TITLE>Internal Server Error</TITLE>
</HEAD><BODY>
<H1>Internal Server Error - Write</H1>
The server encountered an internal error or
misconfiguration and was unable to
complete your request.
And this is my code with curl.
curl -X POST -u "apikey:{apikey}" \
--header "Content-Type: audio/mp3" \
--data-binary #{path_to_file} \
"https://gateway-tok.watsonplatform.net/speech-t
o-text/api/v1/recognize?model=jaJP_BroadbandModel"
You have a typo in the model, it should be ja-JP_BroadbandModel
Try this code
Note that: After the {url} , you must type /v1/recognize
*audio-file.flac is the name of the audio file
curl -X POST -u "apikey:{apikey}" ^
--header "Content-Type: audio/flac" ^
--data-binary #{audio file path}audio-file.flac ^
"{url}/v1/recognize"
Happy coding :)

login to page using html form and cookies for authentication

I'm trying to login to this page using curl. The page uses authentication via html forms so http auth using curl --user name:password is not working in this case. I've found this post where is mentioned that one should search for
action= attribute under <form> to obtain correct address where to send data. The snippet from mentioned page looks following:
<form id="si_signinform" name="signinform" method="post" action="https://www.criticker.com/authenticate.php">
<input class="si_input" name="si_username" id="si_input_uname" value="" autocapitalize="none" type="text">
<input class="si_input" name="si_password" id="si_input_pswd" value="" type="password">
<input name="goto" value="https://www.criticker.com/signout.php" type="hidden">
<p id="submit"><input id="si_submit" name="si" value="Go" type="submit"></p>
I've also find this post which says that some attributes might be hidden when the are send to server (seems that this is my case because of "goto" and "si" parameters as shown on screenshots)
So here are steps I did:
I've logged to page via Firefox
I've check HTTP parameters via Developer Tools (see screenshots)
I've issued following curl command to login curl -L -X POST -F 'si_uername=wakatana' -F 'si_password=$PASWORD' -F 'goto=https://www.criticker.com/signout.php' -F 'si=Go' -c cookiefile.txt http://www.criticker.com/authenticate.php
Then I've issued following curl command to check whether I'm logged successfully curl -L -b cookiefile.txt https://www.criticker.com/
When I login from Firefox I can see my username in upper right of page.
But when I issue one of the curl commands and grep the returned content for username there is no such string. Based on this I deduce that authentication was not successful. But when login via Firefox and use "Copy as cURL" function as stated here I got this:
curl "https://www.criticker.com/" -H "Host: www.criticker.com" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" -H "Accept-Language: en-US,en;q=0.5" --compressed -H "Referer: https://www.criticker.com/signin.php" -H "Cookie: PHPSESSID=SOME_VALUES_GOES_HERE; gid2=SOME_VALUES_GOES_HERE; uid2=SOME_VALUES_GOES_HERE -H "Connection: keep-alive" -H "Upgrade-Insecure-Requests: 1" -H "DNT: 1"
and it works. The problem is that I need to first login wit Firefox and then issue curl.
How can I use curl to login to page which is using forms? Please note I'm looking for some general hints which I can apply to any page (e.g. using proxy, sniffers etc.). I'm not primary interested in this site (but I'm interesting why the curl commands does not work). It is just example which uses form for authentication, if there is some playground for testing such curl commands please let me know. Thank you
Your cURL command is incorrect. Typo in si_username and missing the S in https for the authentication page. Also, in the "goto" you are putting the singout page instead of the main page (or some other page).
Try with:
curl -L -F 'si_username=name' -F 'si_password=xxx' -F 'goto=https://www.criticker.com/' -F 'si=Go' -c cookiefile.txt https://www.criticker.com/authenticate.php
You may not even need the goto and Go fields:
curl -L -F 'si_username=name' -F 'si_password=xxx' -c cookiefile.txt https://www.criticker.com/authenticate.php

Page Not Found error while searching Marklogic transforms

I'm trying to implement transforms in Marklogic using example from this link
When I try to install transform using following curl command
curl --anyauth --user admin:admin -X PUT -d#"./add-attr.xqy" -H "Content-type: application/xquery" 'http://localhost:8000/LATEST/config/transforms/add-attr?trans:name=string\?&trans:value=string\?'
it's giving me errors like (using curl)
<div><h3>Message</h3><div style="width: 100%; height: 300px; overflow: auto;"><pre><error:error xsi:schemaLocation="http://marklogic.com/xdmp/error error.xsd" xmlns:error="http://marklogic.com/xdmp/error" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<error:code>XDMP-BADREP</error:code>
<error:name>err:FORX0004</error:name>
<error:xquery-version>1.0-ml</error:xquery-version>
<error:message>Invalid replacement string</error:message>
<error:format-string>XDMP-BADREP: (err:FORX0004) fn:replace("/LATEST/config/transforms/add-attr", attribute{fn:QName("", "uri")}{"^/(common-api|dashboard|history|manage|nav|packaging|rest-apis)(..."}, &lt;rest:uri-param name="url" xmlns:rest="http://marklogic.com/appservices/rest"&gt;/LATEST/config/transforms/add-attr?trans:name=string\?&amp;amp;trans...&lt;/rest:uri-param&gt;) -- Invalid replacement string: /LATEST/config/transforms/add-attr?trans:name=string\?&amp;trans:value=string\?</error:format-string>
<error:retryable>false</error:retryable>
<error:expr>fn:replace("/LATEST/config/transforms/add-attr", attribute{fn:QName("", "uri")}{"^/(common-api|dashboard|history|manage|nav|packaging|rest-apis)(..."}, &lt;rest:uri-param name="url" xmlns:rest="http://marklogic.com/appservices/rest"&gt;/LATEST/config/transforms/add-attr?trans:name=string\?&amp;amp;trans...&lt;/rest:uri-param&gt;)</error:expr>
<error:data>
<error:datum>/LATEST/config/transforms/add-attr?trans:name=string\?&amp;trans:value=string\?</error:datum>
I even tried using Postman-chrome app and it's giving me 401 Unauthorized error.
even when I'm checking for available transforms using
http://localhost:8000/v1/config/transforms
It's giving me Page Not Found exception
I'm trying with admin user which have all the admin permissions
What am I missing here? How can I build transform for REST calls?
I am getting the same error, but only if I run the above command against MarkLogic 7. MarkLogic 7 is not running a REST-api on port 8000, that is new in MarkLogic 8.
Next to this you should use url encoding instead of regex escaping for the question mark in trans:xxx request parameter values, e.g.:
curl --anyauth --user admin:admin -X PUT -d#"./add-attr.xqy" -H "Content-type: application/xquery" 'http://localhost:8000/LATEST/config/transforms/add-attr?trans:name=string%3F&trans:value=string%3F'
HTH!