.net 调用WebClient.DownloadFile时Matlab登录和下载失败

.net 调用WebClient.DownloadFile时Matlab登录和下载失败,.net,matlab,.net,Matlab,我已经设法让matlab登录到google Trends下载csv数据。首先,我使用DownloadString,然后将其转换为matlab字符串,然后使用fastawrite保存csv文件 但是,即使字符串被正确下载,“\n”行也丢失了一些格式…这是因为如果我按“\n”将文件拆分为单元格数组,格式就可以了 因此,我现在正试图让DownloadFile方法工作,但我一直遇到以下错误: 找不到类“System.Net.WebClient”具有匹配签名的方法“DownloadFile” 非常感谢,

我已经设法让matlab登录到google Trends下载csv数据。首先,我使用DownloadString,然后将其转换为matlab字符串,然后使用fastawrite保存csv文件

但是,即使字符串被正确下载,“\n”行也丢失了一些格式…这是因为如果我按“\n”将文件拆分为单元格数组,格式就可以了

因此,我现在正试图让DownloadFile方法工作,但我一直遇到以下错误:

找不到类“System.Net.WebClient”具有匹配签名的方法“DownloadFile”

非常感谢,

下面是函数:

NET.addAssembly('System.Net');

url = 'https://www.google.com/accounts/ClientLogin?accountType=GOOGLE&Email=email&Passwd=pass&service=trendspro&source=test-test-v1';
durl = System.String(strcat('http://www.google.com/trends/viz?q=', keyWord, '&date=all&geo=all&graph=all_csv&sort=0&scale=1&sa=N'));

if exist('googleWebClient','var')
    client = googleWebClient;
else
    client = System.Net.WebClient;

    response = client.DownloadString(url);
    sid = char(response.ToString);
    sid = regexp(sid, '\n', 'split'); sid = sid(1,1);

    client.Headers.Add('Cookie', char(sid));
    assignin('base','googleWebClient',client);
end

saveFilePath = System.String(strcat('C:\Dropbox\PROJECTS\', keyWord, '.csv'));


data = client.DownloadFile(durl, saveFilePath);

丢失了哪种格式?听起来您可能只是获取Unix模式(\n)文本,然后在DOS模式(\r\n)编辑器中打开它。一个快速的
regexprep(sid,'\r?\n',sprintf('\r\n'))
将解决这个问题。切换到下载文件可能不会

就您得到的“无此方法”错误而言,
WebClient.DownloadFile
的返回类型为void。看起来Matlab的.NET支持考虑了签名的这一部分。删除“data=”分配,它就会消失

>> client = System.Net.WebClient;
>> x = client.DownloadFile('http://www.cnn.com', 'C:\temp\blah.html')
No method 'DownloadFile' with matching signature found for class 'System.Net.WebClient'.

>> client.DownloadFile('http://www.cnn.com', 'C:\temp\blah.html')
>> 

非常感谢你!!我一直禁止我的头靠在墙上……我删除了data=并且它正在按原样下载csv文件。似乎当我使用char(data)函数将System.String转换为matlab char,然后使用fastawrite保存时,某种程度上破坏了格式。对不起,regexprep(sid)格式很好,我使用的是DownloadString而不是DownloadFile,由于某种原因,csv文件中出现了一些格式错误。。。