public int getUrlRespStreamBytes(ref Byte[] respBytesBuf,
string url,
Dictionary<string, string> headerDict,
Dictionary<string, string> postDict,
int timeout,
Action<int> funcUpdateProgress)
{
int realReadoutLen = 0;
getUrlRespStreamBytes_bw(ref respBytesBuf, url, headerDict, postDict, timeout, funcUpdateProgress);
while (bNotCompleted_download)
{
System.Windows.Forms.Application.DoEvents();
}
realReadoutLen = gRealReadoutLen;
//clear
gRealReadoutLen = 0;
return realReadoutLen;
}
例 9.9. getUrlRespStreamBytes 的使用范例
public bool downloadStMusicFile(string musicRealAddr, string fullnameToStore, out string errStr, Action<int> funcUpdateProgress)
{
bool downloadOk = false;
errStr = "未知错误!";
if (musicRealAddr == null ||
musicRealAddr == "" ||
fullnameToStore == null ||
fullnameToStore == "")
{
errStr = "Songtaste歌曲真实的地址无效!";
return downloadOk;
}
Dictionary<string, string> headerDict = new Dictionary<string, string>();
//headerDict.Add("Referer", "http://songtaste.com/music/");
headerDict.Add("Referer", "http://songtaste.com/");
//const int maxMusicFileLen = 100 * 1024 * 1024; // 100M
const int maxMusicFileLen = 300 * 1024 * 1024; // 300M
Byte[] binDataBuf = new Byte[maxMusicFileLen];
int respDataLen = crl.getUrlRespStreamBytes(ref binDataBuf, musicRealAddr, headerDict, null, 0, funcUpdateProgress);
if (respDataLen < 0)
{
errStr = "无法读取歌曲数据!";
return downloadOk;
}