Https Get Headers

Hello,

Is there a way to set the headers on an https get requet using .Q.hg?

ie I need to send auth token and content-type

Thanks

.Q.hg is a wrapper around .Q.hmb - it defaults the y and z arguments to `GET and ()

.Q.hmb accepts the full 3 arguments

If you put a print statement (0N!) right before ($y) within .Q.hmb you can see the string request it builds without interrupting the execution. It helps to see what’s going on.

The z arg is used to set the content-type and content-length headers (if you have a look at the penultimate if-else within .Q.hmb you will see what it does with z).

But knowing that, you can technically use z to add other headers:

//adding print statement

\d .Q

k)hmb2:{p:^/$getenv$_:(“HTTP”;“NO”),:“_PROXY”;u:hap@-1!x;t:~(^*p)||/(*“:”:u 2)like/:{((“.”=*x)#“*”),x}'“,”:$p 1;a:$[t;p:hap@-1!*p;u]1;(4+*r ss d)_r:(-1!`$,/($[t;p;u]0 2))0N!($y)," “,$[t;1_$x;u 3],” HTTP/1.1",s,(s/:(“Connection: close”;“Host: “,u 2),((0<#a)#,$[t;“Proxy-”;””],“Authorization: Basic “,((-c)_.Q.b6@,/64:‘256/:’“i”$0N 3#a,c#0),(c:.q.mod[-#a;3])#”=”),$[#z;(“Content-type: “,z 0;“Content-length: “,$#z 1);()]),(d:s,s:”\r\n”),$[#z;z 1;””]}

\d .

PS - dont change .Q functions, this is only for show.

now you can run the likes of:

//text content-type

q)a:.Q.hmb2[$":http://www.google.com/finance/historical?q=LON%3AFDP&output=csv";GET;(“text”;())]

“GET /finance/historical?q=LON%3AFDP&output=csv HTTP/1.1\r\nConnection: close\r\nHost: www.google.com\r\nContent-type: text\r\nContent-length: 0\r\n\r\n”

//html content-type

q)a:.Q.hmb2[$":http://www.google.com/finance/historical?q=LON%3AFDP&output=csv";GET;(“html”;())]

“GET /finance/historical?q=LON%3AFDP&output=csv HTTP/1.1\r\nConnection: close\r\nHost: www.google.com\r\nContent-type: html\r\nContent-length: 0\r\n\r\n”

//text content type with base64 encoded user:pass

q)a:.Q.hmb2[$":http://www.google.com/finance/historical?q=LON%3AFDP&output=csv";GET;("text \r\n Authorization: Basic ",string .Q.j10 “sohagan:pass”;())]

“GET /finance/historical?q=LON%3AFDP&output=csv HTTP/1.1\r\nConnection: close\r\nHost: www.google.com\r\nContent-type: text \r\n Authorization: Basic -8621435969492112596\r\nContent-length: 0\r\n\r\n”

and the results are stored in the variable a too. You can modify ‘Basic’ to be ‘Oauth’ or whatever you require.

HTH,

Sean

Thanks a lot for this answer Sean.

Roni Hoffman