webclient

Is it safe to use the same CookieContainer across multiple HttpWebRequests?

与世无争的帅哥 提交于 2019-12-05 18:51:47
I am doing a kind of WebCrawler and I need to persist the Cookies state between requests. I download all pages async creating new HttpWebRequest instances, but setting the same CookieContainer. The pages can write and read cookies. Can I do it safely? There is any alternative that isn´t subclass the CookieContainer and put locks at all method? The MSDN says that this class isn´t thread safe, but in practice, can I do it? According to the documentation : Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe. So

Pass two JSON object by web client post method C#

爱⌒轻易说出口 提交于 2019-12-05 18:31:57
I need to pass below object as a parameter for a post method using web client method in C#. { "company": { "id": "e63dfcab345260b2591f585126ede56627db4ef2" }, "requestor": { "id": "", "email": "customer@example.com ", "firstName": "Test", "lastName": "Requestor", "role": "employerAdmin", "phone": "(415)1112222", "title": "HR Manager" } } I converted like this company[id]=e63dfcab345260b2591f585126ede56627db4ef2&requestor[id]=&requestor[email]=customer@example.com+&requestor[firstName]=Test&requestor[lastName]=Requestor&requestor[role]=employerAdmin&requestor[phone]=(415)1112222&requestor[title

Should WebClient be used in a using statement?

我只是一个虾纸丫 提交于 2019-12-05 16:51:48
If HttpClient is not supposed to be used in a using statement, see these links: https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/ http://www.nimaara.com/2016/11/01/beware-of-the-net-httpclient/ So if your not supposed to use HttpClient in a using statement then why do so many examples out there put WebClient in a using statement (including Microsoft); also I have not yet seen an article about not putting WebClient in a using statement? Eventually at the lowest level both WebClient and HttpClient end up at the same place opening a TCP/IP socket. Is it what's in-between that makes

A connection attempt failed because the connected party did not properly respond after a period of time or connected host has failed to respond

坚强是说给别人听的谎言 提交于 2019-12-05 16:46:57
I'm developing a windows service, that downloads images from a specific URL. The service runs correctly on my computer but when I install it in the server it does not download the image and it gives the following error: System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 212.100.220.117:80 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot,

How to enter password automatically in Webview

我与影子孤独终老i 提交于 2019-12-05 12:35:01
I am new to Java and Android and I got a question. I think the solution is maybe very easy but I couldn't solve it. I created an application with a WebView the thing is I want that the webview enters username and password automatically so that the user is already logged in when he starts the application. I googled it and found something like that but it does not work @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); webView = (WebView) findViewById(R.id.webView1); webView.getSettings().setJavaScriptEnabled

webclient methods not available to my Silverlight application

江枫思渺然 提交于 2019-12-05 12:32:49
Trying to do basic webclient data pull in C#, and the methods are not available in visualstudio, and the code is not compiling. //snip WebClient client = new WebClient(); byte[] resp = client.DownloadData(url); //snip Error 1 'System.Net.WebClient' does not contain a definition for 'DownloadData' and no extension method 'DownloadData' accepting a first argument of type 'System.Net.WebClient' could be found (are you missing a using directive or an assembly reference?) C:\Users\Michael\Documents\Visual Studio 2008\Projects\search2\search2\MainPage.xaml.cs I'm doing this in a c# file for a XAML

Mono WebClient encoding issue

对着背影说爱祢 提交于 2019-12-05 12:25:44
I'm trying to port a .NET application from Windows to Mono, but certain code that was working on Windows is no longer working ( as expected ) on mono : WebClient client = new WebClient (); Console.WriteLine (client.DownloadString("http://www.maxima.fm/51Chart/")); it seems to detect correctly the encoding as UTF-8 (and manually setting the encoding to UTF-8 or ASCII don't work either) there are still '?' characters You are writing to the console. Maybe your console is not configured properly to show certain characters. Make sure by debugging and storing the result into an intermediary variable

WebClient download string (a few chars page) is so slow

老子叫甜甜 提交于 2019-12-05 12:00:19
I am trying to download a string from an URL. Unfortunately, it is very slow. Here is my code: // One of these types for two bad solutions anyway // byte[] result = new byte[12]; // string result; using (var webClient = new System.Net.WebClient()) { String url = "http://bg2.cba.pl/realmIP.txt"; //result = webClient.DownloadString(url); // slow as hell //webClient.OpenRead(url).Read(result, 0, 12); // even slower } It takes about 4-5 seconds, which seems very inappropriate to me... Content of this url is IP XX.YYY.ZZ.FF Fixed, sorry for putting this question here I guess, but... here is working

WebClient.CancelAsync — File still downloading

梦想与她 提交于 2019-12-05 11:56:36
I'm trying to create a Web API using Asp.NET Core that exposes routes to start and cancel long downloads of large files. The server should be able to handle multiple downloads at the same time. The download is performed using WebClient.DownloadFileAsync in order to have a short response time and returning a downloadId for later use. The instance of the WebClient is stored as value in a static dictionary whose corresponding key is of naturally the downloadId . The download should be canceled using WebClient.CancelAsync on the instance of the client retrieved by accessing the value of the

WebClient DownloadString UTF-8 not displaying international characters

谁说胖子不能爱 提交于 2019-12-05 11:33:55
I attempt to save the html of a website in a string. The website has international characters (ę, ś, ć, ...) and they are not being saved to the string even though I set the encoding to be UTF-8 which corresponds to the websites charset. Here is my code: using (WebClient client = new WebClient()) { client.Encoding = Encoding.UTF8; string htmlCode = client.DownloadString(http://www.filmweb.pl/Mroczne.Widmo); } When I print "htmlCode" to the console, the international characters are not shown correctly even though in the original HTML they are shown correctly. Any help is appreciated. I had the