這是我想出的解決方案。
這將返回客戶對象
private RestClient InitializeAndGetClient()
{
var cookieJar = new CookieContainer();
var client = new RestClient("https://xxxxxxx")
{
Authenticator = new HttpBasicAuthenticator("xxIDxx", "xxKeyxx"),
CookieContainer = cookieJar
};
return client;
}
,你可以使用的方法類似
var client = InitializeAndGetClient();
var request = new RestRequest("report/transaction", Method.GET);
request.AddParameter("option", "value");
//Run once to get cookie.
var response = client.Execute(request);
//Run second time to get actual data
response = client.Execute(request);
希望這有助於你。
Prakash。