I'm a beginner and I want to write a Nim-application that processes some data from an internal website. Basic authentication (username, password) is required to access this site.
A working Python solution is:
response = requests.get('https://internal:PORT/page',
auth=('user', 'passwd'),
verify=False) # this is vital
Based on the nim doc regarding httpclient and the modules source code, where it is stated that one could use a proxy as an argument for any of the functions, I've been trying something along these lines:
var
client = newHttpClient()
prox = newProxy("https://internal:PORT/page", "user:passwd")
let response = client.getContent(prox) # Error: type mismatch
The solution is probably very obvious but I'm out of ideas on how to authenticate.
If anybody could help, that'd be highly appreciated!
Basic auth is just an "Authorization" header with value "Basic " + base64(username + ":" + password). Equivalent in nim:
import httpclient, base64
var
client = newHttpClient()
var username = ...
var password = ...
client.headers["Authorization"] = "Basic " & base64.encode(username & ":" & password)
# ... send request with the client
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With