Tag: webclient

在C#中暂停/恢复上传

我正在寻找一种通过C#的WebClient暂停或恢复上传过程的方法。 伪代码: WebClient Client = new WebClient(); Client.UploadFileAsync(new Uri(“http://mysite.com/receiver.php”),“POST”,“C:\ MyFile.jpg”); 也许像.. Client.Pause(); 任何的想法?

WebClient UploadFileAsync正在进行报告中的奇怪行为

我需要一些奇怪的WebClient.UploadFileAsync()的行为帮助。 我正在将文件上传到远程HTTP服务器(nginx)usind POST方法。 POST通过PHP脚本(地址引用)处理。 我有这个简单的代码 public void uploadFile(string filePath) { webClient = new WebClient(); webClient.Credentials = new NetworkCredential(Constant.HTTPUsername,Constant.HTTPPassword); webClient.Headers.Add(“Test”, TestKey); webClient.UploadProgressChanged += webClient_UploadProgressChanged; webClient.UploadFileCompleted += webClient_UploadFileCompleted; try { webClient.UploadFileAsync(new Uri(Address), “POST”, filePath); } catch (Exception error) { throw new CustomException(error.Message); } } 在UploadProgressChanged中,我只需使用给定的ProgressPercentage更新progressBar。 第一个问题是报告的进度百分比,任何文件大小为: [17.38.14] Progress: 0 Bytes Sent: 175 / 269264 [17.38.14] Progress: 1 […]

如何在WebClient.DownloadStringAsync URL中使用String

我目前有这个用于我的WebClient URL WebClient Detail = new WebClient(); Detail.DownloadStringCompleted += new DownloadStringCompletedEventHandler(Detail_DownloadStringCompleted); Detail.DownloadStringAsync(new Uri(“http://api.trademe.co.nz/v1/Listings/” + ListingID.Text + “.xml”)); 我想要做的是使用这个字符串: void ListBoxSelectionChanged(object sender, SelectionChangedEventArgs args) { var lbi = ((sender as ListBox).SelectedItem as TradeItem); if(lbi != null) { string id = lbi.ListingId.ToString(); } } 作为WbeClient URL的一部分。 例: WebClient Detail = new WebClient(); Detail.DownloadStringCompleted += new DownloadStringCompletedEventHandler(Detail_DownloadStringCompleted); Detail.DownloadStringAsync(new […]

处理WebClient.DownloadString的正确方法的exception

我想知道在使用WebClient.DownloadString时我应该保护自己的exception。 这是我目前正在使用它的方式,但我相信你们可以建议更好的更强大的exception处理。 例如,我的头顶: 没有网络连接。 服务器返回404。 服务器超时。 处理这些情况并将exception抛出到UI的首选方法是什么? public IEnumerable FindUpcomingGamesByPlatform(string platform) { string html; using (WebClient client = new WebClient()) { try { html = client.DownloadString(GetPlatformUrl(platform)); } catch (WebException e) { //How do I capture this from the UI to show the error in a message box? throw e; } } string relevantHtml = “” […]

使用WebClient获取远程图像会产生粒状GIF,无法处理PNG + BMP

问候! 我正在创建一个Web表单原型(ImageLaoder.aspx),它将返回一个图像,以便它可以像其他Web表单/网页这样的简单示例一样使用: 到目前为止,它加载JPG没有问题,但是与原始数据相比,GIF看起来“颗粒状”,而BMP和PNG导致以下exception: System.Runtime.InteropServices.ExternalException:GDI +中发生一般错误 到目前为止我的代码看起来像这样: protected void Page_Load(object sender, EventArgs e) { string l_filePath = Request.QueryString[“i”]; System.Drawing.Image l_image = GetImage(l_filePath); if (l_image != null) { System.Drawing.Imaging.ImageFormat l_imageFormat = DetermineImageFormat(l_filePath); WriteImageAsReponse(l_image, l_imageFormat); } } private System.Drawing.Image GetImage(string filePath) { WebClient l_WebClient = new WebClient(); byte[] l_imageBytes = l_WebClient.DownloadData(filePath); System.Drawing.Image l_image = null; using (MemoryStream l_MemStream […]

使用WebClient在Unity3d中下载大文件

我正在寻找有关使用WebClient在Unity3d中下载大(100mg +)文件的任何想法。 WWW以异步方式运行并且完美无缺,除非它返回内存错误并导致应用程序崩溃,因此我已按照此处所述移至解决方案: 如何从url下载文件并使用C sharp中的unity3d保存在位置? 这就像一个梦想, 除了它关闭我的应用程序中的所有脚本,直到下载完成。 我似乎甚至无法在下载进行的同时运行加载栏。 我试过通过添加一个协程来处理下载,但到目前为止,没有运气。 任何帮助,将不胜感激。 我的代码目前(经过多次迭代后)看起来像: C# void Update() { //Sets up the timer so I can use it to watch the debugging timer += Time.deltaTime; Debug.Log (timer); //Checks to see if the file was already downloaded and saved. If not, it begins downloading. if (FileExists == 0 && timer […]

如何在C#中使用webclient UploadFile,UploadValues上传多个文件?

如何在C#中使用webclient UploadFile,UploadValues上传多个文件?

在C#中使用Web客户端时是否存在上载限制?

使用带有WebClient的UploadFile(“upload.php”,“POST”,filePath)不会上传任何超过4mb的内容。 PHP的限制设置为48mb。 我需要在C#中设置吗?

将WebClient错误作为字符串获取

我有一个测试Web服务的诊断工具。 我希望工具在出现问题时进行报告,因此我已经部署了一个服务,但合同有问题需要对其进行测试。 当我浏览它时,我得到一个带有描述性信息的页面,例如: ExceptionDetail,可能由IncludeExceptionDetailInFaults = true创建,其值为:System.InvalidOperationException:在对WSDL导出扩展的调用中抛出exception: System.ServiceModel.Description.DataContractSerializerOperationBehavior契约:类型XXX的DataContract无法添加到DataContractSet,因为名称空间XXX中具有相同数据协定名称XXX的类型XXX已存在且合同不等同等。 我想要的是能够打电话: myErrorMsg = WebClient.DownloadString(“MyBadService.svc”); 并将此有用的错误消息作为字符串,但我得到以下WebException: 远程服务器返回错误:(500)内部服务器错误。 如何在浏览器中收到的相同错误消息作为字符串返回,而不会出现exception? 谢谢。

WebClient中的POST数组(C#/ .net)

我有一个.net应用程序,它有一个WebRequest,它给POST添加了多次相同的键,从而使它成为PHP,Java Servlets等眼中的数组。我想重写这个使用WebClient,但如果我多次使用相同的键调用WebClient的QueryString.Add(),它只是附加新值,使用逗号分隔的单个值而不是值数组。 我使用WebClient的UploadFile()发布我的请求,因为除了这些元数据,我想要一个文件发布。 如何使用WebClient发布值数组而不是单个值(逗号分隔值)? 干杯 聂