webrequest

C# Async WebRequests: Perform Action When All Requests Are Completed

大兔子大兔子 提交于 2020-01-01 07:05:23
问题 I have this basic scraping console application in C# that Asynchronously uses WebRequest to get html from a list of sites. It works fine, but how do I set up a trigger that goes off when every site in the list has been processed? I've spent a couple hours researching various solutions online, including the MS docs, but none of them provide a straight forward answer via code. I've read about the IAsyncResult.AsyncWaitHandle but I have no clue how to integrate it into my code. I'd just like to

C# Async WebRequests: Perform Action When All Requests Are Completed

百般思念 提交于 2020-01-01 07:05:01
问题 I have this basic scraping console application in C# that Asynchronously uses WebRequest to get html from a list of sites. It works fine, but how do I set up a trigger that goes off when every site in the list has been processed? I've spent a couple hours researching various solutions online, including the MS docs, but none of them provide a straight forward answer via code. I've read about the IAsyncResult.AsyncWaitHandle but I have no clue how to integrate it into my code. I'd just like to

Remote HTTP Post with C# [duplicate]

只愿长相守 提交于 2019-12-30 03:33:11
问题 This question already has answers here : How to make HTTP POST web request (11 answers) Closed 6 years ago . How do you do a Remote HTTP Post (request) in C#? 回答1: This is code from a small app I wrote once to post a form with values to a URL. It should be pretty robust. _formValues is a Dictionary<string,string> containing the variables to post and their values. // encode form data StringBuilder postString = new StringBuilder(); bool first=true; foreach (KeyValuePair pair in _formValues) {

Sending gzipped data in WebRequest?

烈酒焚心 提交于 2019-12-28 13:45:29
问题 I have a large amount of data (~100k) that my C# app is sending to my Apache server with mod_gzip installed. I'm attempting to gzip the data first using System.IO.Compression.GZipStream. PHP receives the raw gzipped data, so Apache is not uncompressing it as I would expect. Am I missing something? System.Net.WebRequest req = WebRequest.Create(this.Url); req.Method = this.Method; // "post" req.Timeout = this.Timeout; req.ContentType = "application/x-www-form-urlencoded"; req.Headers.Add(

Sending gzipped data in WebRequest?

不问归期 提交于 2019-12-28 13:45:08
问题 I have a large amount of data (~100k) that my C# app is sending to my Apache server with mod_gzip installed. I'm attempting to gzip the data first using System.IO.Compression.GZipStream. PHP receives the raw gzipped data, so Apache is not uncompressing it as I would expect. Am I missing something? System.Net.WebRequest req = WebRequest.Create(this.Url); req.Method = this.Method; // "post" req.Timeout = this.Timeout; req.ContentType = "application/x-www-form-urlencoded"; req.Headers.Add(

Creating WPF BitmapImage from MemoryStream png, gif

柔情痞子 提交于 2019-12-27 11:43:12
问题 I am having some trouble creating a BitmapImage from a MemoryStream from png and gif bytes obtained from a web request. The bytes seem to be downloaded fine and the BitmapImage object is created without issue however the image is not actually rendering on my UI. The problem only occurs when the downloaded image is of type png or gif (works fine for jpeg). Here is code that demonstrates the problem: var webResponse = webRequest.GetResponse(); var stream = webResponse.GetResponseStream(); if

Creating WPF BitmapImage from MemoryStream png, gif

﹥>﹥吖頭↗ 提交于 2019-12-27 11:43:10
问题 I am having some trouble creating a BitmapImage from a MemoryStream from png and gif bytes obtained from a web request. The bytes seem to be downloaded fine and the BitmapImage object is created without issue however the image is not actually rendering on my UI. The problem only occurs when the downloaded image is of type png or gif (works fine for jpeg). Here is code that demonstrates the problem: var webResponse = webRequest.GetResponse(); var stream = webResponse.GetResponseStream(); if

C# Webrequest upload file and proceed

☆樱花仙子☆ 提交于 2019-12-25 07:47:31
问题 How can i upload a simple image to www.newocr.com, select a language from the combobox below , click the 'Upload' button and after the 'OCR' button and finnaly getting the string from the source code which stores the string into a id All programatically. Any help? 回答1: follow this link : This Can Help You:: OCR reading using C# http://www.codeproject.com/Questions/157546/C-OCR-How-to-Read-a-single-character-from-image Try This: Bitmap BWImage = new Bitmap(fileName); // Lock destination bitmap

Silverlight WebRequest fails with “The URI prefix is not recognized”

让人想犯罪 __ 提交于 2019-12-25 02:44:47
问题 I have a silverlight library that is supposed to get make a web service request and receive an xml response: Uri uri = new Uri("http://some_server:51306/getStuff.xml?id=14"); WebRequest request = WebRequest.Create(uri); However, WebRequest.Create(uri) fails with the exception "The URI prefix is not recognized". Note that I am running the program using a unit test from a non-silverlight dll. I need to build a test suite for the app! Any ideeas? 回答1: Try setting the .Web project as the default

How to get redirected url as string after request

冷暖自知 提交于 2019-12-25 02:15:34
问题 For example on any tinyurl/ajdeijad link (this one is fake), the think redirects to another url Here is my code: Dim request1 As HttpWebRequest = DirectCast(HttpWebRequest.Create(urlvimeohd), HttpWebRequest) request1.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1" request1.MaximumAutomaticRedirections = 1 request1.AllowAutoRedirect = True How do you retrieve the url of the response (it redirects!) 回答1: The only way I