webrequest

WebRequest BeginGetResponse/EndGetResponse throws exception when using Task.FromAsync

假如想象 提交于 2019-12-03 21:49:46
I try to asyncify the POST operation to a REST web service using the WebRequest. So from what I know already, I need to use the Task.Factory.FromAsync<T>(BeginXyz, EndXyz, null) , seems like its working for the GetRequestStream pair methods, since I get no exception and the byte[] is filled with values. Stream requestStream = await Task.Factory.FromAsync<Stream>( request.BeginGetRequestStream, request.EndGetRequestStream, null); byte[] postBytes = Encoding.UTF8.GetBytes(requestData); await requestStream.WriteAsync(postBytes, 0, postBytes.Length); Fine, the above code is working, and the next

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

只谈情不闲聊 提交于 2019-12-03 21:12:36
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 call a custom function when all threads complete processing or timeout. One trick is that I never know

Copying Http Request InputStream

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 15:28:31
I'm implementing a proxy action method that forwards the incoming web request and forwards it to another web page, adding a few headers. The action method works file for GET requests, but I'm still struggling with forwarding the incoming POST request. The problem is that I don't know how to properly write the request body to the outgoing HTTP request stream. Here's a shortened version of what I've got so far: //the incoming request stream var requestStream=HttpContext.Current.Request.InputStream; //the outgoing web request var webRequest = (HttpWebRequest)WebRequest.Create(url); ... //copy

How to calculate HttpWebRequest spent outbound and inbound internet traffic

别等时光非礼了梦想. 提交于 2019-12-03 08:51:12
问题 I have the below function to fetch a page. My question is i want to calculate how much internet connection is spent Both inbound (download) and outbound traffic (sent) How can i do that ? Thank you My function public static string func_fetch_Page(string srUrl, int irTimeOut = 60, string srRequestUserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0", string srProxy = null) { string srBody = ""; string srResult = ""; try { HttpWebRequest request =

How to calculate HttpWebRequest spent outbound and inbound internet traffic

巧了我就是萌 提交于 2019-12-02 22:41:55
I have the below function to fetch a page. My question is i want to calculate how much internet connection is spent Both inbound (download) and outbound traffic (sent) How can i do that ? Thank you My function public static string func_fetch_Page(string srUrl, int irTimeOut = 60, string srRequestUserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0", string srProxy = null) { string srBody = ""; string srResult = ""; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(srUrl); request.Timeout = irTimeOut * 1000; request.UserAgent = srRequestUserAgent;

How to use WebRequest to POST some data and read response?

谁说我不能喝 提交于 2019-12-02 19:21:05
Need to have the server make a POST to an API, how do I add POST values to a WebRequest object and how do I send it and get the response (it will be a string) out? I need to POST TWO values, and sometimes more, I see in these examples where it says string postData = "a string to post"; but how do I let the thing I am POSTing to know that there is multiple form values? From MSDN // Create a request using a URL that can receive a post. WebRequest request = WebRequest.Create ("http://contoso.com/PostAccepter.aspx "); // Set the Method property of the request to POST. request.Method = "POST"; //

Failed to get response for large file HTTP put create file using c#

做~自己de王妃 提交于 2019-12-02 16:40:07
问题 Failed to get response for large file HTTP put create file using c# I am using file watcher service service monitor, when user created file or folder we are uploading to cloud if file size more than 512 MB it is taking too much time to get the response here I am confusing here the issue with my code or server and reason for this error if any changes on my code suggest me. { var fileFolderObj1 = new FileFolder(); var postURL = apiBaseUri + "/filefolder/create/file/user/" + userId; // +"?type

Failed to get response for large file HTTP put create file using c#

纵饮孤独 提交于 2019-12-02 13:47:58
问题 Failed to get response for large file HTTP put create file using c# I am using file watcher service service monitor, when user created file or folder we are uploading to cloud if file size more than 512 MB it is taking too much time to get the response here I am confusing here the issue with my code or server and reason for this error if any changes on my code suggest me. { var fileFolderObj1 = new FileFolder(); var postURL = apiBaseUri + "/filefolder/create/file/user/" + userId; // +"?type

Failed to get response for large file HTTP put create file using c#

不羁的心 提交于 2019-12-02 11:57:30
Failed to get response for large file HTTP put create file using c# I am using file watcher service service monitor, when user created file or folder we are uploading to cloud if file size more than 512 MB it is taking too much time to get the response here I am confusing here the issue with my code or server and reason for this error if any changes on my code suggest me. { var fileFolderObj1 = new FileFolder(); var postURL = apiBaseUri + "/filefolder/create/file/user/" + userId; // +"?type=file"; code = HttpStatusCode.OK; HttpWebResponse response = null; FileInfo f = new FileInfo(filePath);

Using a timeout callback in async requests

℡╲_俬逩灬. 提交于 2019-12-02 09:11:48
I asked this question before but I'm going to complete the question with a solution proposed and make another question. I'm using this class to make an async WebRequest : class HttpSocket { public static void MakeRequest(Uri uri, Action<RequestCallbackState> responseCallback) { WebRequest request = WebRequest.Create(uri); request.Proxy = null; Task<WebResponse> asyncTask = Task.Factory.FromAsync<WebResponse>(request.BeginGetResponse, request.EndGetResponse, null); ThreadPool.RegisterWaitForSingleObject((asyncTask as IAsyncResult).AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback),