如何解决我无法在WixSharp安装程序中使用RestSharp,是否可以使用HttpClient或WebClient完成此操作?
private async Task<AuthenticationToken> GetToken()
{
string username = loginDialog.username;
string password = loginDialog.password;
string requestString = $"Service/Login";
RestRequest request = new RestRequest(requestString,Method.POST);
request.AddParameter("username",username);
request.AddParameter("password",password);
IRestResponse<AuthenticationToken> response = await _client.ExecuteAsync<AuthenticationToken>(request);
return response.Data;
}
我在解决方案中的一些项目中使用RestSharp。我无法在安装程序中使用它,因为WixSharp在RestSharp上无法正常工作。我需要使用WebClient或HttpClient来获得与使用RestSharp库使用此方法所获得的响应相同的响应。有人能帮忙吗?
解决方法
好的,试试这个
var httpClient = new HttpClient();
var headers = httpClient.DefaultRequestHeaders;
headers.Add("Content-Tpye","application/form-url-encoded");
string requestParams = string.Format("grant_type=password&username={0}&password={1}",username,password);
HttpContent content = new StringContent(requestParams);
var response = httpClient.PostAsync(requestString,content);
var responseContent = await response.Result.Content.ReadAsStringAsync();
然后,您可以使用responseContent
或任何JSON库在NewtonSoft
上使用JSON解串器。
在需要Wixsharm运行时需要一些外部程序集的情况下,只需将其添加如下:
var proj = ManagedProject()
proj.DefaultRefAssemblies.Add("Restsharp.dll")
它可以在运行时加载并且可以访问使用。
P.S。不要忘记在构建器可执行文件的输出位置检查程序集是否存在。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。