Basic authentication is one (somewhat outdated) style of authentication. Most external services won't actually support it. Commonly, web APIs will allow users to generate some kind of long-lived token, and then require that token be passed in an authentication header - with httpClient
, that would look something like this:
client = system.net.httpClient()
headers = {
"Authorization": "Bearer %s" % token
}
response = client.post("url", headers=headers)
Or for a more complete example of wrapping a web API: