我需要以编程方式下载大文件,然后再进行处理.最好的方法是什么?由于文件很大,我想要特定的时间等待,以便我可以强行退出.
我知道WebClient.DownloadFile().但似乎没有办法确定等待一段时间以便强行退出.
try
{
WebClient client = new WebClient();
Uri uri = new Uri(inputFileUrl);
client.DownloadFile(uri, outputFile);
}
catch (Exception ex)
{
throw;
}
Run Code Online (Sandbox Code Playgroud)
另一种方法是使用命令行实用程序(wget)下载文件并使用ProcessStartInfo触发命令并使用Process'WellForExit(int ms)强制退出.
ProcessStartInfo startInfo = new ProcessStartInfo();
//set startInfo object
try
{
using (Process exeProcess = Process.Start(startInfo))
{
//wait for time specified
exeProcess.WaitForExit(1000 * 60 * 60);//wait till 1m
//check if process has exited
if (!exeProcess.HasExited)
{
//kill process and throw ex
exeProcess.Kill();
throw new ApplicationException("Downloading timed out");
}
}
}
catch (Exception ex)
{
throw;
} …Run Code Online (Sandbox Code Playgroud) 我见过几个不同的应用程序,允许用户在他们的PC上拍摄屏幕截图,然后该实用程序将自动将图像上传到Web服务器.我想将这种类型的功能合并到一个新的MVC站点中.
我当然可以让用户上传他们自己的图像,但如果他们可以点击Capture Screen Shot并且图像会自动上传,那就更干净了.
我的团队正在使用带有SQL后端数据库的ASP.NET MVC2.我们当然愿意考虑第三方组件(基于activeX等),这将使我们能够实现这一目标.
谷歌的做法与他们的报告类似.所以闻起来并不是闻所未闻......
我正在使用WebClient的DownloadFileAsync(在C#中)方法异步下载文件.我有事件处理程序附加到DownloadProgressChanged和DownloadFileCompleted事件.我希望通过DownloadFileCompleted事件处理程序中的AsyncCompletedEventArgs的Error属性收到任何错误的通知.如果在下载开始之前没有连接,它可以很好地工作.它错误地解决了,我在上面提到的属性中得到了错误.但是如果在下载过程中连接断开,则不会发生任何事情.事件处理程序未被调用,它会一直等待.我该怎么办才能处理这种情况?谢谢.
我有一个.aspx页面,它有一些控制分页的JavaScript函数.
我可以通过webbrowser运行这个javascript函数,其中包含以下方法 WebBrowser1_DocumentCompleted
WebBrowser1.Document.Window.DomWindow.execscript ("somefunction();", "JavaScript")
Run Code Online (Sandbox Code Playgroud)
webbrowser非常慢,我更喜欢使用System.Net.WebClient.DownloadString.
有一些方法可以使用System.Net.WebClient更快或其他方法运行此脚本吗?
我在C#中构建一个应用程序,它使用com.gargoylesoftware.htmlunit.WebClient来访问和检索来自网页的信息.
我的应用程序从主项目运行良好,但当我尝试构建单元测试来测试项目类时,我收到以下错误:
FactoryConfigurationError
Message "Provider com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl not found"
Source "IKVM.OpenJDK.XML.API" string
StackTrace " at javax.xml.parsers.DocumentBuilderFactory.newInstance()
at com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration.loadConfiguration(Reader configurationReader)
at com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration.loadConfiguration()
at com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration..ctor(BrowserVersion )
at com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration.getInstance(BrowserVersion browserVersion)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine..ctor(WebClient webClient)
at com.gargoylesoftware.htmlunit.WebClient.init(BrowserVersion , ProxyConfig )
at com.gargoylesoftware.htmlunit.WebClient..ctor(BrowserVersion browserVersion)
at com.gargoylesoftware.htmlunit.WebClient..ctor()
at GWT.HeadlessBrowser..ctor() in C:\\hg\\EXE\\GWT\\HeadlessBrowser.cs:line 57
at TestGWT.ProgramTest.TestLogInProcessForGWT() in C:\\hg\\TestGWT\\ProgramTest.cs:line 115"
Run Code Online (Sandbox Code Playgroud)
尝试在单元测试类中创建HtmlUnit WebClient也会导致此错误.
我在主项目和包含单元测试的项目中都有项目引用htmlunit-2.7,IKVM.OpenJDK.Core和IKVM.OpenJDK.XML.API.
我是否需要额外的项目参考才能运行单元测试?可能导致此错误的原因是什么?
测试类使用Microsoft.VisualStudio.TestTools.UnitTesting;
我有一个Web应用程序,它使用JQuery与我的后端进行交互.后端成功接受JSON数据.例如,我可以成功发送以下JSON:
{ "id":1, "firstName":"John", "lastName":"Smith" }
Run Code Online (Sandbox Code Playgroud)
我现在有一个必须打到这个后端的Windows Phone应用程序.我需要通过WebClient传递相同的JSON.目前我有以下内容,但我不确定如何实际传递JSON.
string address = "http://www.mydomain.com/myEndpoint;
WebClient myService = new WebClient();
utilityService.UploadStringCompleted += new UploadStringCompletedEventHandler(utilityService_UploadStringCompleted);
utilityService.UploadStringAsync(address, string.Empty);
Run Code Online (Sandbox Code Playgroud)
有人能告诉我我需要做什么吗?
我获得了一个HTTPCookie,但需要一个Net.Cookie.它们只是你可以重铸的东西,或者我将如何去做?
我正在使用System.Net.WebClient.DownloadString下载JSON.我收到了有效回复:
{
"FormDefinition": [
{
"$id":"4",
"Class":558,
"ClassDisplayLabel":"Punchworks",
"Name":"Punchworks Form"
},
{
"$id":"6",
"Class":558,
"ClassDisplayLabel":"Punchworks",
"Name":"Punchworks Form test second"
},
{
"$id":"46",
"Class":558,
"ClassDisplayLabel":"Punchworks",
"Name":"any_Name"
},
{
"$id":"47",
"Class":558,
"ClassDisplayLabel":"Punchworks",
"Name":"Punchworks Form test second"
},
{
"$id":"49",
"Class":558,
"ClassDisplayLabel":"Punchworks",
"Name":"Testing Name ??´????? ???? ACEeišuu { [ ( ~ ! @ # "
},
{
"$id":"50",
"Class":558,
"ClassDisplayLabel":"Punchworks",
"Name":"something new"
},
{
"$id":"56",
"Class":558,
"ClassDisplayLabel":"Punchworks",
"Name":"Testing Name руÌÑÑкий æ±‰è¯æ¼¢èªž ĄČĘėįšųū { [ ( ~ ! @ # "
},
{
"$id":"57", …Run Code Online (Sandbox Code Playgroud) 我有一个班负责在下载管理器中下载文件.该类负责下载文件并将其写入给定路径.
要下载的文件大小通常在1到5 MB之间变化,但也可能更大.我正在使用WebClient类的实例从Internet获取文件.
public class DownloadItem
{
#region Events
public delegate void DownloadItemDownloadCompletedEventHandler(object sender, DownloadCompletedEventArgs args);
public event DownloadItemDownloadCompletedEventHandler DownloadItemDownloadCompleted;
protected virtual void OnDownloadItemDownloadCompleted(DownloadCompletedEventArgs e)
{
DownloadItemDownloadCompleted?.Invoke(this, e);
}
public delegate void DownloadItemDownloadProgressChangedEventHandler(object sender, DownloadProgressChangedEventArgs args);
public event DownloadItemDownloadProgressChangedEventHandler DownloadItemDownloadProgressChanged;
protected virtual void OnDownloadItemDownloadProgressChanged(DownloadProgressChangedEventArgs e)
{
DownloadItemDownloadProgressChanged?.Invoke(this, e);
}
#endregion
#region Fields
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private WebClient _client;
#endregion
#region Properties
public PlaylistItem Item { get; }
public string SavePath { get; }
public bool Overwrite …Run Code Online (Sandbox Code Playgroud) webclient ×10
c# ×7
download ×2
.net ×1
asp.net ×1
asp.net-mvc ×1
asynchronous ×1
browser ×1
cookies ×1
htmlunit ×1
javascript ×1
jquery ×1
json ×1
json.net ×1
large-files ×1
memory ×1
memory-leaks ×1
screenshot ×1
unit-testing ×1