最近Garmin Connect改变了他们的登录程序,我试图在c#中找到有关如何执行此操作的信息。
我找到了一些关于如何做到这一点的基础知识,但它不起作用:
我看了一下新的登录过程。 Garmin使用所谓的" GAuth小部件"实现了单点登录方法。 您应该能够按如下方式登录。
1)通过向例如HTTP GET请求发送HTTP GET请求来获取GAuth小部件 https://sso.garmin.com/sso/login?ser...edWidget=false
2)解析收到的" flowExecutionKey"的HMTL代码,例如" e1s1"在 代码:
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<!-- flowExecutionKey: [e1s1] -->
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
[...]
3)通过向1)中给出的URL发送HTTP POST请求来发布您的登录凭据,其中包含以下内容: 代码:
_eventId=submit
displayNameRequired=false
embed=true
lt=<YourFlowExecutionKey>
password=<YourPassword>
username=<YourUserName>
4)解析收到的&#34; response_url&#34;的HTML代码,例如Code:
[...]
var redirectAfterAccountLoginUrl = 'http://connect.garmin.com/post-auth/login';
var consumeServiceTicket = 'false';
var service_url = 'http://connect.garmin.com/post-auth/login';
var parent_url = 'http://connect.garmin.com/de-DE/signin';
var response_url = 'http://connect.garmin.com/post-auth/login?ticket=ST-XXXXXX-XXXXXXXXXXXXXXXXXXXX-cas';
var logintoken = '';
var social_uid = '';
[...]
5)通过向响应URL发送HTTP HEAD请求来登录garmin connect。 &#34;服务票&#34; (部分以&#34; ST - &#34;开头)证明您通过GAuth小部件成功登录。
**********************************************************************************************
这是我到目前为止的代码,但它在步骤3中永远不会返回response_url。我缺少什么?
var url = "https://sso.garmin.com/sso/login?service=http%3A%2F%2Fconnect.garmin.com%2Fpost-auth%2Flogin&webhost=olaxpw-connect07.garmin.com&source=http%3A%2F%2Fconnect.garmin.com%2Fus-EN%2Fsignin&redirectAfterAccountLoginUrl=http%3A%2F%2Fconnect.garmin.com%2Fpost-auth%2Flogin&redirectAfterAccountCreationUrl=http%3A%2F%2Fconnect.garmin.com%2Fpost-auth%2Flogin&gauthHost=https%3A%2F%2Fsso.garmin.com%2Fsso&locale=en&id=gauth-widget&cssUrl=https%3A%2F%2Fstatic.garmincdn.com%2Fcom.garmin.connect%2Fui%2Fsrc-css%2Fgauth-custom.css&clientId=GarminConnect&rememberMeShown=true&rememberMeChecked=false&createAccountShown=true&openCreateAccount=false&usernameShown=true&displayNameShown=false&consumeServiceTicket=false&initialFocus=true&embedWidget=false#";
// Step 1
WebClient wc = new WebClient();
var result = wc.DownloadString(url);
string[] splt1 = Regex.Split(result, "<!-- flowExecutionKey: ");
string[] splt2 = Regex.Split(splt1[1], "] -->");
var flowExecutionKey = splt2[0].Replace("[", "");
// Step 2
var formParams = new NameValueCollection();
formParams.Add("_eventId", "submit");
formParams.Add("displayNameRequired", "false");
formParams.Add("embed", "true");
formParams.Add("lt", flowExecutionKey);
formParams.Add("password", "password");
formParams.Add("username", "username");
formParams.Add("service", "http://connect.garmin.com/post-auth/login");
formParams.Add("redirectAfterAccountLoginUrl", "http://connect.garmin.com/post-auth/login");
formParams.Add("redirectAfterAccountCreationUrl", "http://connect.garmin.com/post-auth/login");
formParams.Add("webhost", "olaxpw-connect00.garmin.com");
formParams.Add("clientId", "GarminConnect");
formParams.Add("gauthHost", "https://sso.garmin.com/sso");
formParams.Add("rememberMeShown", "true");
formParams.Add("rememberMeChecked", "false");
formParams.Add("consumeServiceTicket", "false");
formParams.Add("id", "gauth-widget");
formParams.Add("embedWidget", "false");
formParams.Add("cssUrl", "https://static.garmincdn.com/com.garmin.connect/ui/src-css/gauth-custom.css");
formParams.Add("source", "http://connect.garmin.com/en-US/signin");
formParams.Add("createAccountShown", "true");
formParams.Add("openCreateAccount", "false");
formParams.Add("usernameShown", "true");
formParams.Add("displayNameShown", "false");
formParams.Add("initialFocus", "true");
formParams.Add("locale", "en");
using (var wb = new WebClient())
{
var response = wb.UploadValues(url, "POST", formParams);
var responseString = Encoding.Default.GetString(response);
}
感谢您的帮助! 罗恩