C# 使用C登录mint#
我想从mint.com获取一个csv文件,并用C#处理它。我必须登录才能这样做。我遵循了另一篇关于堆栈溢出的文章的建议,并提出了以下代码。不幸的是,我得到的结果不是预期的CSV,而是一个错误页面。有没有洞察到我做错了什么,或者我是如何用另一种方式做这件事的C# 使用C登录mint#,c#,httpwebrequest,webrequest,C#,Httpwebrequest,Webrequest,我想从mint.com获取一个csv文件,并用C#处理它。我必须登录才能这样做。我遵循了另一篇关于堆栈溢出的文章的建议,并提出了以下代码。不幸的是,我得到的结果不是预期的CSV,而是一个错误页面。有没有洞察到我做错了什么,或者我是如何用另一种方式做这件事的 string cookieHeader = CookieHeaderFromMintLogin("myusername","mypassword"); string csvURL = "https://wwws.mint.co
string cookieHeader = CookieHeaderFromMintLogin("myusername","mypassword");
string csvURL = "https://wwws.mint.com/transactionDownload.event?queryNew=&offset=0&filterType=cash&comparableType=8";
string csv = getResponseWithCookies(csvURL, cookieHeader);
string CookieHeaderFromMintLogin(string username, string password)
{
string formUrl = "https://wwws.mint.com/loginJumper.event"; // NOTE: This is the URL the form POSTs to, not the URL of the form (you can find this in the "action" attribute of the HTML's form tag
string formBuilId = HttpUtility.UrlEncode("form-NAjKdtCT8Z5SuyDHTsmRREioaCMXVEJZpt8-9oaSMEY");
string formId = HttpUtility.UrlEncode("mint_auth_mint_com_login_form");
username = HttpUtility.UrlEncode(username);
password = HttpUtility.UrlEncode(password);
string formParams = string.Format("username={0}&password={1}&form_build_id={2}&form_id={3}", username, password, formBuilId,formId);
WebRequest req = WebRequest.Create(formUrl);
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
byte[] bytes = Encoding.ASCII.GetBytes(formParams);
req.ContentLength = bytes.Length;
using (Stream os = req.GetRequestStream())
{
os.Write(bytes, 0, bytes.Length);
}
WebResponse resp = req.GetResponse();
return resp.Headers["Set-cookie"];
}
string getResponseWithCookies(string getUrl, string cookieHeader)
{
string pageSource;
WebRequest getRequest = WebRequest.Create(getUrl);
getRequest.Headers.Add("Cookie", cookieHeader);
WebResponse getResponse = getRequest.GetResponse();
using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
{
pageSource = sr.ReadToEnd();
}
return pageSource;
}
错误是什么?@RonBeyer csv的内容是来自mint的页面:也许你转错了方向 对不起!这里有几件事你可以试试:
- 你解决了吗,乔希?您收到的错误表明您没有正确登录。我同意我没有正确登录。我想了解我发布的代码没有正确登录的原因。最后,我放弃了,下载了一个用Python编写的API。好吧,我正在用C#现在,我发现它是基于令牌的身份验证,所以我正在抓取和重用令牌。如果我弄明白了,我会告诉你的。