I'm trying to figure out how to do a very simple GET call with RestSharp (v.110.2, the latest one by now) using Basic Authentication. With Postman, everything is ok.
This is how I am creating the client object and doing the call:
private static readonly string JOB_STATUS_URL = "jobStatus";
private RestClient client;
private void InizializeClient()
{
if (client == null)
{
string baseUrl = WebConfigurationManager.AppSettings["CarteBaseUrl"];
string usr = WebConfigurationManager.AppSettings["CarteUsername"];
string pwd = WebConfigurationManager.AppSettings["CartePwd"];
var options = new RestClientOptions(baseUrl)
{
Authenticator = new HttpBasicAuthenticator(usr, pwd)
};
client = new RestClient(options);
}
}
[HttpGet]
public ActionResult CheckSiStatus()
{
PorfolioDB db = new PorfolioDB();
try
{
InizializeClient();
var request = new RestRequest(JOB_STATUS_URL)
.AddParameter("name", "test")
.AddParameter("xml", "Y");
var response = client.Get<JobStatusResponse>(request);
}
catch (Exception e)
{
return Json(new
{
error = e.Message
}, JsonRequestBehavior.AllowGet);
}
}
I have already checked all the other similar posts.
Any suggestion?
Thank you!