webclient

Send POST with WebClient.DownloadString in C#

蓝咒 提交于 2019-12-22 02:01:16
问题 I know there are a lot of questions about sending HTTP POST requests with C#, but I'm looking for a method that uses WebClient rather than HttpWebRequest . Is this possible? It'd be nice because the WebClient class is so easy to use. I know I can set the Headers property to have certain headers set, but I don't know if it's possible to actually do a POST from WebClient . 回答1: You can use WebClient.UploadData() which uses HTTP POST, i.e.: using (WebClient wc = new WebClient()) { byte[] result

why my WebClient upload file code hangs?

孤街醉人 提交于 2019-12-21 23:35:13
问题 I am using VSTS 2008 + C# + .Net 3.5 + ASP.Net + IIS 7.0 to develop a Windows Forms application at client side to upload a file, and at server side I receive this file using an aspx file. I find my client side application will hang after click the button to trigger upload event. Any ideas what is wrong and how to solve? Thanks! Client side code, public partial class Form1 : Form { private static WebClient client = new WebClient(); private static ManualResetEvent uploadLock = new

WebClient error when downloading file from https URL

三世轮回 提交于 2019-12-21 17:47:42
问题 Trying to download xml file from https URL (https://nvd.nist.gov/download/nvd-rss.xml) This URL is openly accessible through browser. Using C# Webclient with console project. But getting Exception as below using (WebClient client = new WebClient()) { System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3; client.DownloadFile(uri, @"c:\test\nvd-rss.xml"); } $exception {"The underlying connection was closed: An unexpected error occurred on a send."} System.Net

Get filename without Content-Disposition

六眼飞鱼酱① 提交于 2019-12-21 13:07:57
问题 I am looking for a solution for this problem for days and I can't find any. I want to download a file from a webserver with a webclient. The download works fine, but I can't get the real filename, which is very important for me. I read on many homepages, that the filename should be saved in the Content-Disposition-Header. Unfortunately this header of the site is empty. I tried to get it with: string header_contentDisposition =""; using (WebClient client = new WebClient()) { client.OpenRead

Getting error “Provider com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl not found” in unit test but not in main program

旧城冷巷雨未停 提交于 2019-12-21 10:51:40
问题 I am building an application in C# which uses com.gargoylesoftware.htmlunit.WebClient to access and retrieve information from webpages. My application runs fine from the main project but when I try to build unit tests to test the project classes I get the following error: 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

webclient and expect100continue

蹲街弑〆低调 提交于 2019-12-21 09:18:30
问题 What is the best way to set expect100continue when using WebClient(C#.NET). I have this code below, I still see 100 continue in the header. Stupid apache still complains with 505 error. string url = "http://aaaa.com"; ServicePointManager.Expect100Continue = false; WebClient service = new WebClient(); service.Credentials = new NetworkCredential("username", "password"); service.Headers.Add("Content-Type","text/xml"); service.UploadStringCompleted += (sender, e) => CompleteCallback(BuildResponse

webclient and expect100continue

时光毁灭记忆、已成空白 提交于 2019-12-21 09:17:57
问题 What is the best way to set expect100continue when using WebClient(C#.NET). I have this code below, I still see 100 continue in the header. Stupid apache still complains with 505 error. string url = "http://aaaa.com"; ServicePointManager.Expect100Continue = false; WebClient service = new WebClient(); service.Credentials = new NetworkCredential("username", "password"); service.Headers.Add("Content-Type","text/xml"); service.UploadStringCompleted += (sender, e) => CompleteCallback(BuildResponse

The remote name could not be resolved - webclient

浪子不回头ぞ 提交于 2019-12-21 09:06:16
问题 I am facing this error : The remote name could not be resolved: 'russgates85-001-site1.smarterasp.net' When I request html contents to read using web client it gives me error. Below is my code. string strHTML = string.Empty; WebClient myClient = new WebClient(); UTF8Encoding utf8 = new UTF8Encoding(); byte[] requestHTML; string pdfFileName = "outputpdf_" + DateTime.Now.Ticks + ".pdf"; string webUrl = Request.Url.Scheme + "://" + Request.Url.Host + (Request.Url.Port != 80 ? ":" + Request.Url

System.Net.WebClient fails weirdly

北战南征 提交于 2019-12-21 07:29:24
问题 I am trying to download some data from the reporting services instance on our TFS server. Given that the code should run on a computer that is not domain-joined, I figured that I would set the credentials myself. No luck, got a HTTP 401 Unauthorized back. Ok, so I hooked up Fiddler to see what was happening. But that's when I got Heisenberged - the call now went through without a hitch. So the authentication goes through with Fiddler connected, but fails without it. Is the Webclient broken or

System.Net.WebClient fails weirdly

旧街凉风 提交于 2019-12-21 07:29:07
问题 I am trying to download some data from the reporting services instance on our TFS server. Given that the code should run on a computer that is not domain-joined, I figured that I would set the credentials myself. No luck, got a HTTP 401 Unauthorized back. Ok, so I hooked up Fiddler to see what was happening. But that's when I got Heisenberged - the call now went through without a hitch. So the authentication goes through with Fiddler connected, but fails without it. Is the Webclient broken or