https - C# DownloadFileTaskAsync not downloading nested zip file -
please c# newbie,
i'm trying download zipped files https site script task in ssis. each "external" zip file contains "internal" zip file, contains 3 txt files.
after extensive search, i've enhanced downloadfiletaskasync "await", ".wait()" , "while (webclient.isbusy) still manage download empty "external" zip file.
please me find way download full "external" file in way won't empty, contain "internal" zip , 3 txt files inside of it:
public async void main() { webclient webclient = new webclient(); webclient.credentials = new networkcredential("myuser", "password", "https://example.com/login.htm"); webclient.downloadfiletaskasync(new uri("https://example.com/#/fromsender/external_20160706.zip"), @"c:\temp\test\external_20160706.zip").wait(); while (webclient.isbusy) thread.sleep(1000); dts.taskresult = (int)scriptresults.success; }
>
try one, add headers webclient:
public async void main() { webclientex webclient = new webclientex(); // <= use webclientex webclient.credentials = new networkcredential("myuser", "password", "https://example.com/login.htm"); // add headers here ------------ webclient.headers.add("user-agent", "mozilla/5.0 (windows nt 10.0; wow64) applewebkit/537.36 (khtml, gecko) chrome/51.0.2704.79 safari/537.36"); webclient.headers.add("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); webclient.headers.add("accept-language", "en-us,en;q=0.5"); webclient.headers.add("accept-encoding", "gzip, deflate"); webclient.headers.add("cache-control", "max-age=0"); webclient.headers.add("dnt", "1"); //------------------------------ webclient.downloadfiletaskasync(new uri("https://example.com/#/fromsender/external_20160706.zip"), @"c:\temp\test\external_20160706.zip").wait(); while (webclient.isbusy) thread.sleep(1000); dts.taskresult = (int)scriptresults.success; }
and use class instead of webclient:
public class webclientex : webclient { protected override webrequest getwebrequest(uri address) { var webrequest = (httpwebrequest) base.getwebrequest(address); if (webrequest != null) { webrequest.automaticdecompression = decompressionmethods.gzip | decompressionmethods.deflate; } return webrequest; } }
Comments
Post a Comment