Tag: webclient

在unit testing中获取错误“Provider com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl”但在主程序中没有

我在C#中构建一个应用程序,它使用com.gargoylesoftware.htmlunit.WebClient来访问和检索来自网页的信息。 我的应用程序从主项目运行良好,但当我尝试构建unit testing来测试项目类时,我收到以下错误: 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″ 尝试在unit testing类中创建HtmlUnit WebClient也会导致此错误。 我在主项目和包含unit testing的项目中都有项目引用htmlunit-2.7,IKVM.OpenJDK.Core和IKVM.OpenJDK.XML.API。 […]

WebClient – 远程服务器返回错误:(403)禁止

从浏览器打开公共页面工作正常。 使用WebClient下载同一页面抛出 – (403)禁止。 这里发生了什么 ? 以下是Web上特定页面的快速复制/粘贴示例(在控制台应用程序上使用): try { WebClient webClient = new WebClient(); string content = webClient.DownloadString(“http://he.wikisource.org/wiki/%D7%A9%D7%95%D7%9C%D7%97%D7%9F_%D7%A2%D7%A8%D7%95%D7%9A_%D7%90%D7%95%D7%A8%D7%97_%D7%97%D7%99%D7%99%D7%9D_%D7%90_%D7%90”); } catch (Exception ex) { throw; }

当服务器具有有效的SSL证书时,使用带有“https”的WebClient.UploadFile()时,“握手失败…意外的数据包格式”

我试图使用WebClient.UploadFile与HTTPS URL,但我最终得到 “System.IO.IOException:由于意外的数据包格式,握手失败” 相同的代码与Http完全正常,但我想要的服务器有一个非常好的ssl证书。 以下是与网络电话相关的任何内容: var url = WebServiceCommunication.GetProtocolName() + “…”; //turns out to be “https://… var wc = new WebClient(); //I am adding: wc.Headers.Add(HttpRequestHeader.KeepAlive, “…”) wc.Headers.Add(HttpRequestHeader.AcceptLanguage, “…”) we.Headers.Add(HttpRequestHeader.Cookie, “…”) wc.UploadFile(url, “POST”, filename); 我正在添加和使用https的任何HttpRequestHeaders的问题是什么? 或者,如果我想使用https,我是否错过了必要的标题? 当SSL证书有效时,有没有人指出为什么这可以用于HTTP而不是HTTPS?

WebClient设置标头

我如何在webClient类中设置标题? 我试过了: client.Headers[“Content-Type”] = “image/jpeg”; 抛出WebException 我的代码: WebClient client = new WebClient(); client.Headers.Set(“Content-Type”, “image/png”); client.Headers.Set(“Content-Length”, length); client.Headers.Add(“Slug”, name); NameValueCollection nvc = new NameValueCollection(); nvc.Add(“file”, FileContents); Byte[] data = client.UploadValues(url, nvc); string res = Encoding.ASCII.GetString(data); Response.Write(res);

为什么我的WebClient上传文件代码挂起?

我正在使用VSTS 2008 + C#+。Net 3.5 + ASP.Net + IIS 7.0在客户端开发Windows窗体应用程序以上载文件,在服务器端我使用aspx文件接收此文件。 我发现单击按钮触发上传事件后,我的客户端应用程序将挂起。 任何想法有什么不对,怎么解决? 谢谢! 客户端代码, public partial class Form1 : Form { private static WebClient client = new WebClient(); private static ManualResetEvent uploadLock = new ManualResetEvent(false); private static void Upload() { try { Uri uri = new Uri(“http://localhost/Default2.aspx”); String filename = @”C:\Test\1.dat”; client.Headers.Add(“UserAgent”, “TestAgent”); client.UploadProgressChanged += […]

如何在WebClient.DownloadFileAsync上实现超时

所以我认为Webclient.DownloadFileAysnc会有一个默认超时,但环顾文档我无法在任何地方找到任何关于它的东西所以我猜它没有。 我试图从互联网上下载文件,如下所示: using (WebClient wc = new WebClient()) { wc.DownloadProgressChanged += ((sender, args) => { IndividualProgress = args.ProgressPercentage; }); wc.DownloadFileCompleted += ((sender, args) => { if (args.Error == null) { if (!args.Cancelled) { File.Move(filePath, Path.ChangeExtension(filePath, “.jpg”)); } mr.Set(); } else { ex = args.Error; mr.Set(); } }); wc.DownloadFileAsync(new Uri(“MyInternetFile”, filePath); mr.WaitOne(); if (ex != null) […]

WebClient.DownloadStringAsync在Silverlight中抛出安全exception

第一次使用Silverlight! 在线教程之后。 我正在创建一个应用程序,允许用户使用WebClient从Digg网站搜索故事,并将它们显示在Silverlight控件的数据网格中。 这是代码: private void btnSearch_Click(object sender, RoutedEventArgs e) { string topic = txtTopic.Text; string diggUrl = String.Format(“http://services.digg.com/stories/topic/{0}?count=20&appkey=http%3A%2F%2Fscottgu.com”, topic); WebClient diggService = new WebClient(); diggService.DownloadStringCompleted += new DownloadStringCompletedEventHandler(diggService_DownloadStringCompleted); diggService.DownloadStringAsync(new Uri(diggUrl)); } void diggService_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { if (e.Error == null) { DisplayStories(e.Result); } } 每当我在diggService_DownloadStringCompleted事件处理程序上设置diggService_DownloadStringCompleted并单击搜索按钮时, e.Error始终等于没有消息的System.Security.SecurityException和具有“安全错误”消息的相同类型的内部exception。 堆栈跟踪是: 在System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod,Object state) 在System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) 在System.Net.WebClient.GetWebResponse(WebRequest请求,IAsyncResult结果) […]

C#WebClient OpenReadurl

所以我有这个程序使用短链接获取页面(我使用谷歌url缩短器)。 为了构建我的示例,我使用了在C#中使用WebClient的代码, 有没有办法在重定向后获取站点的URL? using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Net; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { MyWebClient client = new MyWebClient(); client.OpenRead(“http://tinyurl.com/345yj7x”); Uri uri = client.ResponseUri; Console.WriteLine(uri.AbsoluteUri); Console.Read(); } } class MyWebClient : WebClient { Uri _responseUri; public Uri ResponseUri { get { return _responseUri; […]

System.Net.WebClient在UploadString期间没有抛出错误到无效的url?

鉴于此代码,我预计会发生exception,但System.Net.WebClient.UploadString会将空字符串返回到result 。 我显然忽略了什么,但是什么? using System.Net; using System.Text; [TestClass()] public class WebClientTests { [TestMethod()] public void WebClientUploadStringToInvalidUrlTest() { var webClient = new WebClient { Encoding = Encoding.UTF8 }; var result = webClient.UploadString(“{{foo-bar}}”, “snafu”); Assert.IsTrue(string.IsNullOrEmpty(result)); } [TestMethod()] [ExpectedException(typeof(ArgumentNullException))] public void WebClientUploadStringToNullUrlTest() { var webClient = new WebClient { Encoding = Encoding.UTF8 }; string url = null; var […]

如何在.net上为WebClient设置TimeOut?

我下载了一些文件,但我也想为webclient设置超时。 正如我所看到的那样,我们可以使用重写WebRequest。 我已经做了但它没有用。 我的意思是重写GetWebRequest方法不起作用..这是我的代码 public class VideoDownloader : Downloader { /// /// Initializes a new instance of the class. /// /// The video to download. /// The path to save the video. public VideoDownloader(VideoInfo video, string savePath) : base(video, savePath) { } /// /// Starts the video download. /// public override void Execute() { // […]