Hi, I cannot find any info about using custom headers with getContent() procedure. I'm trying this code:
from httpclient import getContent
from httpclient import get
var headers = ""
var ur = "https://ololo.com/getInfo/"
var auth_key = "blahblahblahmanychars"
var order_id = 1111
headers = headers & "auth_key:" & auth_key & "\c\L"
headers = headers & "order_id:" & $order_id & "\c\L"
echo(headers)
echo(getContent(ur, extraHeaders=headers))
But response is
{"status":1,"auth_key":null,"status_message":"error_login"}
Do I do something wrong or it's something with server?
Also I get the same result when using
echo(getContent(ur))
Thank you
I newbie in web programming, sorry for stupid question.
So solution for that is making get-request to address?auth_key=abrakadabra&order_id=12345
getContent("https://address/api/?auth_key=abrakadabra&order_id=12345")
Headers and params are two different things.
Headers are (for example):
Params are key-value-pairs which are sent to the server as a query string.
As far as I understand the lib, the headers are for http headers defined in RFC2616, RFC2047 (Custom X-Headers) and RFC6648 (Deprecation of custom X-headers). If you want to submit a query_string you have to build it your own. With python requests library, it is possible to do a "params=params" and the params are added as query_string to the url but I haven't found a similiar way to do this with httpclient.
I may completely wrong because I am new to nim. Perhaps one of the nim geeks would/should answer you.
I think this can help with parameters
https://github.com/achesak/exthttp.nim/blob/master/exthttp.nim