KDB:.Q.hp/.Q.hg 和内置 HTTP 请求之间的区别。 persist/Keep 还活着吗?

KDB: Difference between .Q.hp/.Q.hg and the built in HTTP request. And do either persist/Keep alive?

似乎可以使用 .Q.hg 或使用

等内置 HTTP 请求来执行 http get

`:http://host:port "作为 HTTP 方法等发送的字符串" (来自 https://code.kx.com/q/kb/programming-examples/

有什么区别吗?

默认情况下 persist/keep-alive?

谢谢

.Q.hg 和 .Q.hp 具有与 link 中概述的示例类似的功能,无需将 HTTP 请求构造为字符串(这些函数将构造字符串为你)。该示例可能是在 v3.4 中引入 .Q.hg/.Q.hp 函数之前编写的。

假设他们使用 HTTP 1.0 协议,我不认为默认情况下会持续存在。

使用 .Q.hg 允许您使用格式与基于网络的 url 请求一致的字符串,例如从服务器请求一些 csv 数据:

t:.Q.hg`$":http://www.website.com/report1/format=csv&cols=sym&cols=price&date=20200630";
/the resulting string contains the data only (no metadata/headers) and can be parsed directly
("SF";1#csv)0:t

GET 等价物不像浏览器 url,但它确实 return metadata/headers(这反过来使解析更混乱),例如

t:(hsym`$"http://www.website.com") "GET /report1/format=csv&cols=sym&cols=price&date=20200630 HTTP/1.1\r\nhost:www.website.com\r\n\r\n";
/result looks like
"HTTP/1.1 200 OK\r\nDate: Fri, 03 Jul 2020 14:46:33 GMT\r\nContent-Type: application/txt\r\nContent-Length: 1345\r\nConnection: keep-alive ...."
/parsed using something like (strip away metadata to get to the data)
("SF";1#csv)0:_[;t]3+first t ss "\n\r\n"

结果 metadata/header 在我刚测试过的示例中显示“Connection: keep-alive”,也许这是默认设置?我对此不是 100%。

.Q.hg 还具有与 HTTPS 兼容并根据文档使用代理的优势:https://code.kx.com/q/ref/dotq/#qhg-http-get