2012-07-06 56 views
1

我想建立一個服務登錄到在線銀行網站並下載用戶的最新交易信息。.NET HTTPS請求 - 發佈數據登錄到網站

我建立它在.NET/C#,我試圖按照我看到的關於如何做到這一點另一篇文章的例子... .NET HTTP POST Method - Cookies issue

但我似乎無法讓示例工作。

,我試圖登錄到是該網站... http://www.communityamericacu.com/

這裏是我想出迄今...

public void RetrieveTransactions() 
{ 
    var request = (HttpWebRequest) WebRequest.Create("https://secureaccess.cacu.com/accountlink/SignOn/SignOn.aspx"); 
    var cookies = new CookieContainer(); 
    request.CookieContainer = cookies; 
    request.Method = "POST"; 
    request.ContentType = "application/x-www-form-urlencoded"; 

    using (var requestStream = request.GetRequestStream()) 
    { 
     using (var writer = new StreamWriter(requestStream)) 
     { 
      writer.Write("user=****&PIN=****&BankFolder=Banking&BrandID=1&BrandFolder=cacu&BrandType=R&screenwidth=&screenheight=&RemoteLogin=N&ExitURL=&UserJavaPlatForm=Win32&UserJavaBrowser=Netscape&UserJavaVersion=5.0+%28Windows+NT+6.1%3B+WOW64%29+AppleWebKit%2F536.11+%28KHTML%2C+like+Gecko%29+Chrome%2F20.0.1132.47+Safari%2F536.11&UserJavaCodeName=Mozilla&UserJavaColorDepth=32&UserJavaColors=4294967296&UserJavaCurrentResolution=1600x900&UserJavaMaxResolution=1600x870&UserJavaEnabled=Yes&UserJavaAAFonts=No&UserJavaPlugins=+Remoting+Viewer+Native+Client+Chrome+PDF+Viewer+Shockwave+Flash+Shockwave+Flash+Adobe+Acrobat+Microsoft+Lync+2010+Meeting+Join+Plug-in+QuickTime+Plug-in+7.7.2+QuickTime+Plug-in+7.7.2+QuickTime+Plug-in+7.7.2+QuickTime+Plug-in+7.7.2+QuickTime+Plug-in+7.7.2+QuickTime+Plug-in+7.7.2+QuickTime+Plug-in+7.7.2+Microsoft+Office+2010+Microsoft+Office+2010+Google+Update+NVIDIA+3D+Vision+NVIDIA+3D+VISION+Java%28TM%29+Platform+SE+7+U5+Java+Deployment+Toolkit+7.0.50.255+Shockwave+for+Director+Silverlight+Plug-In+Remoting+Viewer+Native+Client+Chrome+PDF+Viewer+Shockwave+Flash+Shockwave+Flash+Adobe+Acrobat+Microsoft+Lync+2010+Meeting+Join+Plug-in+QuickTime+Plug-in+7.7.2+QuickTime+Plug-in+7.7.2+QuickTime+Plug-in+7.7.2+QuickTime+Plug-in+7.7.2+QuickTime+Plug-in+7.7.2+QuickTime+Plug-in+7.7.2+QuickTime+Plug-in+7.7.2+Microsoft+Office+2010+Microsoft+Office+2010+Google+Update+NVIDIA+3D+Vision+NVIDIA+3D+VISION+Java%28TM%29+Platform+SE+7+U5+Java+Deployment+Toolkit+7.0.50.255+Shockwave+for+Director+Silverlight+Plug-In&UserJavaUTCOffset=5"); 
     } 
    } 

    using (var responseStream = request.GetResponse().GetResponseStream()) 
    { 
     if (responseStream != null) 
     { 
      using (var reader = new StreamReader(responseStream)) 
      { 
       var result = reader.ReadToEnd(); 
      } 
     } 
    } 

} 

但是,這是響應我得到...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head> 
    <title>@ccountLink Error</title> 
</head> 
<body> 
An error occurred. 
</body> 
</html> 

當我嘗試登錄到網站時,即使使用不正確的用戶名和密碼,這也不是我得到的結果。

在這一點上,這些東西都比我頭腦清醒。任何幫助,我可以得到將不勝感激。

+0

這聽起來很腥。由於ViewState驗證可能無法實現。 – jrummell 2012-07-06 15:18:25

回答

0

銀行是否可以檢查HTTP請求的附加字段,例如用戶代理(即瀏覽器),以及何時找不到它會給出錯誤?嘗試添加至少一個用戶代理(在您關聯的問題中有一個示例)。也許你還必須添加其他字段。你可以在這裏看到完整的列表http://en.wikipedia.org/wiki/List_of_HTTP_header_fields