webrequest

HttpWebRequest times out on second call

狂风中的少年 提交于 2019-11-27 00:53:54
Why does the following code Timeout the second (and subsequent) time it is run? The code hangs at: using (Stream objStream = request.GetResponse().GetResponseStream()) and then causes a WebException saying that the request has timed out. I have tried this with a WebRequest and HttpWebRequest Edit: It seems the code is falling over in request.GetResponse() Edit: This post suggests it may be a GC issue --> http://www.vbforums.com/showthread.php?t=610043 - as per this post the issue is mitigated if Fiddler is open in the background. The server is there and available for requests. private string

Cannot send a content-body with this verb-type

北战南征 提交于 2019-11-27 00:33:26
I just got this exception (ProtocolViolationException) in my .NET 2.0 app (running on windows mobile 6 standard emulator). What confuses me is that as far as i know, I have not added any content body, unless I've inadvertently done it somehow. My code is below (very simple). Is there anything else i need to do to convince .NET that this is just a http GET? Thanks, brian //run get and grab response WebRequest request = WebRequest.Create(get.AbsoluteUri + args); request.Method = "GET"; Stream stream = request.GetRequestStream(); // <= explodes here XmlTextReader reader = new XmlTextReader(stream

C#: Downloading a URL with timeout

懵懂的女人 提交于 2019-11-27 00:32:10
问题 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. 回答1: 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

HttpWebRequest or WebRequest - Resume Download ASP.NET

不问归期 提交于 2019-11-27 00:24:35
问题 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. 回答1: Resuming files is done by specifying the byte range of the file you would like to download using the

WebRequest “HEAD” light weight alternative

与世无争的帅哥 提交于 2019-11-26 23:24:07
问题 I recently discovered that the following does not work with certain sites, such as IMDB.com. class Program { static void Main(string[] args) { try { System.Net.WebRequest wc = System.Net.WebRequest.Create("http://www.imdb.com"); //args[0]); ((HttpWebRequest)wc).UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/0.2.153.1 Safari/525.19"; wc.Timeout = 1000; wc.Method = "HEAD"; WebResponse res = wc.GetResponse(); var streamReader = new

how to change originating IP in HttpWebRequest

半世苍凉 提交于 2019-11-26 22:09:25
I'm running this application on a server that has assigned 5 IPs. I use HttpWebRequest to fetch some data from a website. But when I make the connection I have be able to specify which one of the 5 IPs to make the connection from. Does HttpWebRequest support this? If it doesn't can I inherit a class from it to change it's behavior? I need so ideas here. My code right now is something like: System.Net.WebRequest request = System.Net.WebRequest.Create(link); ((HttpWebRequest)request).Referer = "http://application.com"; using (System.Net.WebResponse response = request.GetResponse()) {

Test if a website is alive from a C# application

做~自己de王妃 提交于 2019-11-26 21:43:22
I am looking for the best way to test if a website is alive from a C# application. Background My application consists of a Winforms UI , a backend WCF service and a website to publish content to the UI and other consumers. To prevent the situation where the UI starts up and fails to work properly because of a missing WCF service or website being down I have added an app startup check to ensure that all everything is alive. The application is being written in C#, .NET 3.5, Visual Studio 2008 Current Solution Currently I am making a web request to a test page on the website that will inturn test

Using WebClient or WebRequest to login to a website and access data

不想你离开。 提交于 2019-11-26 20:17:44
I'm trying to access restricted data on a website using WebClient / WebRequest . There is no official API in that website, so what I'm trying to do is simply fill the HTML form and post the values to the server, so I'm logged in. I tried this and this , but it doesn't look like the upcoming requests are logged in. The latter example is much more appealing since I obviously prefer WebClient , but legacy WebRequest will do. Anyway, in the first example I think it did login, but the upcoming requests that access the private data return a page with a message "This is member only content". How to

What makes this HTTPS WebRequest time out even though it works in the browser?

此生再无相见时 提交于 2019-11-26 19:41:54
问题 Here's my request: var request = (HttpWebRequest) WebRequest.Create("https://mtgox.com/"); request.CookieContainer = new CookieContainer(); request.AllowAutoRedirect = false; request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; request.Headers[HttpRequestHeader.AcceptEncoding] = "gzip, deflate"; request.Headers[HttpRequestHeader.AcceptLanguage] = "en-gb,en;q=0.5"; request.Headers[HttpRequestHeader.AcceptCharset] = "ISO-8859-1,utf-8;q=0.7,*;q=0.7"; request

Multithreading a large number of web requests in c#

你。 提交于 2019-11-26 19:10:13
问题 I have an program where I need to create some large number of folders to an external sharepoint site (external meaning I can't use the sharepoint object model). Web requests work well for this, but simply doing them one at a time (send request, wait for response, repeat) is rather slow. I decided to multithread the requests, to try and speed it up. The program has sped up considerably, but after some amount of time (between 1-2 minutes or so), concurrency exceptions start getting thrown. Code