webrequest

Sending gzipped data in WebRequest?

☆樱花仙子☆ 提交于 2019-11-28 09:07:32
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("Content-Encoding: gzip"); System.IO.Stream reqStream = req.GetRequestStream(); GZipStream gz = new

Asynchronously Load an Image from a Url to a PictureBox

旧时模样 提交于 2019-11-28 05:31:32
问题 I want to load image from the web on windows forms application, Everything is good and code works fine, but the problem is the app stop working until the loading goes to finish. I want to see and work with app without waiting to loading . PictureBox img = new System.Windows.Forms.PictureBox(); var request = WebRequest.Create(ThumbnailUrl); using (var response = request.GetResponse()) using (var stream = response.GetResponseStream()) { img.Image = Bitmap.FromStream(stream); } 回答1: Here is the

Login to instagram programmatically

ⅰ亾dé卋堺 提交于 2019-11-28 05:26:45
问题 I am trying to log in to instagram using web requests. I am having a bad time understanding what's going on. Getting this: The remote server returned an error: (403) Forbidden. What I have so far: public static string csrf; CookieContainer c1 = new CookieContainer(); private void button1_Click(object sender, EventArgs e) { string PostData = String.Format("csrfmiddlewaretoken={0}&username=ra123&password=ra12345678",getToken()); HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("https:

c# Webrequest Post and GetResponse

爷,独闯天下 提交于 2019-11-28 05:21:07
问题 I am writing a program that will submit a XML to a website. The code written works fine, but sometimes it just stops working for some reason, throwing a System.Net.ProtocolViolationException. I can close the program and re-run - it starts working again just fine. Here is the code that I am using: private string Summit(string xml) { string result = string.Empty; StringBuilder sb = new StringBuilder(); try { WebRequest request = WebRequest.Create(this.targetUrl); request.Timeout = 800 * 1000;

C#: Downloading a URL with timeout

放肆的年华 提交于 2019-11-28 04:36:07
What's the best way to do it in .NET? I always forget what I need to Dispose() (or wrap with using ). EDIT: after a long time using WebRequest , I found out about customizing WebClient . Much better. Syncronous Way: var request = HttpWebRequest.Create("http://www.contoso.com"); request.Timeout = 50000; using (var response = request.GetResponse()) { //your code here } You can also have the asynchronous way: using System; using System.Net; using System.IO; using System.Text; using System.Threading; public class RequestState { // This class stores the State of the request. const int BUFFER_SIZE =

HttpWebRequest or WebRequest - Resume Download ASP.NET

你离开我真会死。 提交于 2019-11-28 04:25:53
I would like to know if there is a way to know if a server supports resume download functionallity and if supported, how do I send a request to resume? I was looking for a solution where my ASP.NET page can do a download from a server to mine, something like " rapidleech " does today, but I would like to check if the server where i'm requesting the download supports resume functionallity. Resuming files is done by specifying the byte range of the file you would like to download using the Range HTTP header. This can be done in .NET with the HttpWebRequest.AddRange function. For example: request

Mocking WebResponse's from a WebRequest

放肆的年华 提交于 2019-11-28 03:57:05
I have finally started messing around with creating some apps that work with RESTful web interfaces, however, I am concerned that I am hammering their servers every time I hit F5 to run a series of tests.. Basically, I need to get a series of web responses so I can test I am parsing the varying responses correctly, rather than hit their servers every time, I thought I could do this once, save the XML and then work locally. However, I don't see how I can "mock" a WebResponse, since (AFAIK) they can only be instantiated by WebRequest.GetResponse How do you guys go about mocking this sort of

Sending POST data with C#

亡梦爱人 提交于 2019-11-28 01:33:17
问题 This is the method that I'm trying to use to send POST data to a URL and bring back its response: public string sendPOST(string URL, string postData) { byte[] byteArray; Stream webpageStream; StreamReader webpageReader; String webpageContent; byteArray = Encoding.UTF8.GetBytes(postData); _webRequest = WebRequest.Create(URL); _webRequest.Method = "POST"; _webRequest.ContentType = "application/x-www-form-urlencoded"; _webRequest.ContentLength = byteArray.Length; webpageStream = _webRequest

C# WebRequest.getResponse(): 400 Bad Request

血红的双手。 提交于 2019-11-28 00:05:05
I am trying to download a file from a server using System.Web. It actually works, but some links give me trouble. The links look like this: http://cdn.somesite.com/r1KH3Z%2FaMY6kLQ9Y4nVxYtlfrcewvKO9HLTCUBjU8IBAYnA3vzE1LGrkqMrR9Nh3jTMVFZzC7mxMBeNK5uY3nx5K0MjUaegM3crVpFNGk6a6TW6NJ3hnlvFuaugE65SQ4yM5754BM%2BLagqYvwvLAhG3DKU9SGUI54UAq3dwMDU%2BMl9lUO18hJF3OtzKiQfrC/the_file.ext The code looks basically like this: HttpWebRequest request = (HttpWebRequest)WebRequest.Create(link); WebResponse response = request.getResponse(); getResponse() always throws an exception (Error 400 Bad Request). However, I

How to send a POST with a JSON in a WebRequest() call using MQL4?

萝らか妹 提交于 2019-11-27 18:51:19
问题 I would like to send a POST from MQL4 -script, using a JSON-format to a Node-server. I've tried the webRequest() standard function in MQL4 , based on the following documentation, but it did NOT success. From MQL4 Documentation: Sending simple requests of type "key=value" using the header `Content-Type: application/x-www-form-urlencoded`. int WebRequest( const string method, // HTTP method const string url, // URL const string cookie, // cookie const string referer, // referer int timeout, //