本文介绍了webclient in autohotkey的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这有效:
This works:
URLDownloadToFile, https://www.nseindia.com/content/historical/EQUITIES/2016/JAN/cm01JAN2016bhav.csv.zip, C:\Users\Dave\Desktop\Happy.zip
但我不明白为什么即使URL语法或格式相同也不会这样:
But I donot understand why this does not even if the URL syntax or format is same:
URLDownloadToFile, https://www.nseindia.com/content/historical/EQUITIES/2015/DEC/cm31DEC2015bhav.csv.zip, C:\Users\Dave\Desktop\Sad.zip
我的尝试:
我发现以下用C#编写的方法来自但我的AHK技能非常有限。你能帮忙将下面的C#转换成AHK吗?
What I have tried:
I found the below method written in C# from social.msdn for the same issue but my AHK skills are very limited. Could you help convert the below C# to AHK?
WebClient objWebClient = new WebClient();
Uri uriWebClient = new Uri(url);
objWebClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
objWebClient.Headers.Add("Content-Type", "application / zip, application / octet - stream");
objWebClient.Headers.Add("Accept-Encoding", "gzip,deflate,sdch");
objWebClient.Headers.Add("Referer", "http://Something");
objWebClient.Headers.Add("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
objWebClient.DownloadFile(uriWebClient, filepath);
推荐答案
objWebClient.Headers.Add("Referer", "https://www.nseindia.com/products/content/equities/equities/archieve_eq.htm");
Download( UrlToFile, SaveFileAs:="", Overwrite := True, headers := "", method := "GET", postData := "")
{
MsgBox, %headers%
WinHttpObj := ComObjCreate( "WinHttp.WinHttpRequest.5.1" )
WinHttpObj.Open( method, UrlToFile )
For header, value in headers
WinHttpObj.SetRequestHeader( header, value )
WinHttpObj.Send( postData )
ADODBObj := ComObjCreate( "ADODB.Stream" )
ADODBObj.Type := 1
ADODBObj.Open()
ADODBObj.Write( WinHttpObj.ResponseBody )
If !SaveFileAs
{
urlSplitArray := StrSplit( UrlToFile, "/" )
SaveFileAs := urlSplitArray[ urlSplitArray.MaxIndex() ]
}
ADODBObj.SaveToFile( SaveFileAs, Overwrite ? 2:1 )
ADODBObj.Close()
}
customHeaders := { "User-Agent": "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"
,"Content-Type": "application / zip, application / octet - stream""application / zip, application / octet - stream"
,"Accept-Encoding": "gzip,deflate,sdch"
,"Referer": "https://www.nseindia.com/products/content/equities/equities/archieve_eq.htm"
,"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" }
Download( "https://www.nseindia.com/content/historical/EQUITIES/2015/DEC/cm31DEC2015bhav.csv.zip", "C:\Users\Dave\Desktop\Happy.zip", True, customHeaders )
这篇关于webclient in autohotkey的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!