我正在构建一个Web API以与MYOB网站和站点内容进行通信。通过包含客户端ID和密钥的生成的URL,我可以打开登录页面。成功登录后,我会通过电子邮件收到安全密码,必须在新的身份验证页面中键入该密码。如果代码正确,那么我将被重定向到一个页面,该页面为我提供了访问站点内容的代码。
我使用过System.Diagnostics.Process.Start(redirectUrl);
来打开登录页面,我可以手动完成所有过程。但是我需要我的代码来处理所有过程。所以我使用HttpClient如下:
public static Task<string> GetCode(string url)
{
try
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(url);
client.DefaultRequestHeaders.Accept.Add(
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("text/plain"));
HttpResponseMessage response = client.GetAsync("authorize").Result;
return response.Content.ReadAsStringAsync();
}
catch (Exception)
{
return null;
}
}
代码仅返回“找不到错误”。