问题
In Python I can successfully make a request (with authorization passing) by doing:
def send_request(self, url, public_key, secret_key):
session = requests.session()
session.auth = (public_key, secret_key)
return session.get(url)
I'm trying to replicate this in C# but it's not authorizing:
RestClient client = new RestClient(url);
RestRequest request = new RestRequest(url_stuff, Method.GET);
request.AddHeader(public_key, secret_key);
return client.Execute(request).Content;
What am I missing here?
回答1:
session.auth = (public_key, secret_key)
in python is shorthand for Basic authentication, with public_key
being user name and secret_key
a password. To do the same with RestClient
you need to:
RestClient client = new RestClient(url);
client.Authenticator = new HttpBasicAuthenticator(public_key, secret_key);
return client.Execute(request).Content;
来源:https://stackoverflow.com/questions/47490511/equivalent-of-pythons-request-session-auth-in-c-sharp-net