2022.09.06 03:17 AM - edited 2022.09.06 03:24 AM
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?
I also tried without 'Content-Type: ', just .h.ty` json
2022.09.06 05:36 AM - edited 2022.09.06 05:39 AM
You can use a second q process help you to debug.
Set a Listening-port \p and have the HTTP Post handler (.z.pp) print incoming message contents
\p 5000
.z.pp:{show x;x}
Trying curl from command line
$ curl -H 'Content-type: application/json' -d '{"text":"Hello World"}' localhost:5000
The server q process prints:
" {\"text\":\"Hello World\"}"
`Host`User-Agent`Accept`Content-type`Content-Length!("localhost:5000";"curl/7.58.0";"*/*";"application/json";"22")
From a client q process using .Q.hp
q).Q.hp["http://localhost:5000";.h.ty`json] .j.j enlist[`text]!enlist"Hello World"
The server q process prints:
" {\"text\":\"Hello World\"}"
`Accept-Encoding`Connection`Host`Content-type`Content-length!("gzip";"close";"localhost:5000";"application/json";"22")
There are only slight differences in the headers.
You may need to consult documentation of the server you are connecting to to confirm if it has specific header requirements.
(Clients using KX Insights have access to kurl with more options than .Q.hp)
EMEA
Tel: +44 (0)28 3025 2242
AMERICAS
Tel: +1 (212) 447 6700
APAC
Tel: +61 (0)2 9236 5700
KX. All Rights Reserved.
KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.