0
我一直在嘗試使用Web客戶端這樣的下載銀行對賬單中OFX格式:下載銀行對賬單文件與Web客戶端
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Data;
using System.Collections.Specialized;
namespace DownloadBankStatement
{
class Program
{
static void Main(string[] args)
{
using (var client = new system.net.CookieAwareWebClient())
{
var LoginValues = new NameValueCollection
{
{"newCardNumber","XXXXXXXXXXXXXXXXXXX"},
{"pswPassword","XXXX"}
};
client.UploadValues("https://www.cibconline.cibc.com/olbtxn/authentication/SignOn.cibc", "POST", LoginValues
var PostValues = new NameValueCollection
{
{"selectedAccount","XXXXX,XXXXXXX"},
{"selectedCriteria","2"},
{"fromDateMonth","2"},
{"fromDateDay","7"},
{"fromDateYear","2017"},
{"toDateMonth","2"},
{"toDateDay","7"},
{"toDateYear","2017"},
{"selectedFMSPackage","3"}
};
byte[] Statement = client.UploadValues("https://www.cibconline.cibc.com/olbtxn/accounts/TransactionDownload2.cibc", "POST", PostValues);
File.WriteAllBytes("C:\\Statement.aso", Statement);
}
Console.ReadLine();
}
}
}
namespace system.net
{
public class CookieAwareWebClient : WebClient
{
public CookieContainer CookieContainer { get; private set; }
public CookieAwareWebClient()
{
this.CookieContainer = new CookieContainer();
}
public CookieAwareWebClient(CookieContainer cookieContainer)
{
this.CookieContainer = cookieContainer;
}
protected override WebRequest GetWebRequest(Uri address)
{
var request = base.GetWebRequest(address) as HttpWebRequest;
if (request == null) return base.GetWebRequest(address);
request.CookieContainer = CookieContainer;
return request;
}
}
}
一切工作正常,除了我得到的迴應是web頁面包含我設置銀行對帳單參數的第二個表單。
我檢查POST細節表示:
內容處置:附件;文件名= cibc.aso 內容長度:20052 內容類型:應用程序/ vnd.accpac.simply.aso
當我張貼的形式使用手動IE總是有一個彈出窗口,詢問我要麼保存或打開它直截了當,但是當我使用Chrome來做同樣的事情時,沒有人會問及這個文件是直接下載的。
那麼什麼是正確的方式來保存cibc.aso文件,這顯然是一個附件在這裏?您的反饋非常感謝。