httpwebresponse

Why am I getting a "double response" from HttpWebResponse?

The follow code (running in ASP.Net 2.0) displays the contents of the requested URL twice. I only want it to display the contents of the requested URL once. I can't figure out what I'm doing wrong. The URL requested is returning XML and if I visit the URL directly, it works fine. HttpWebRequest request = (HttpWebRequest)WebRequest.Creat...

Django Authentication from .NET using HttpWebRequest and HttpWebResponse via HTTP POST

I am creating an application in .NET that will serve as a second UI for my already-deployed Django app. For some operations users need to authenticate themselves (as Django users). I used a super-simple way to do this (without encrypting credentials for simplicity):- Step 1. I created a django view that accepted the username and passwor...

How do i get detailed info from a HttpWebResponse

Hi I'm making a post httpwebrequst, but in the HttpWebResponse im getting an error code 403 forbidden. Now that error isnt very use full to me. I then tried a testprogram (that i do not have the source code to :() and used it to make the same post, and it returned with a code 403 forbidden but also told me tha SSL was needed. So is it...

Sockets in C#: How to get the response stream?

Hi I'm trying to replace this: void ProcessRequest(object listenerContext) { var context = (HttpListenerContext)listenerContext; Uri URL = new Uri(context.Request.RawUrl); HttpWebRequest.DefaultWebProxy = null; HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(URL); httpWebRequest.Method = context.Re...

C# Xml in Http Post Request Message Body

Hello, I am looking for an example of how, in C#, to put a xml document in the message body of a http request and then parse the response. I've read the documentation but I would just like to see an example if there's one available. Does anyone have a example? thanks ...

WebRequest get page w/o exceptions?

I want to check the status of a page (404, moved, etc). How can i do it? ATM i am doing the below which only tells me if the page exist or not. Also, i suspect the exception is making my code slow (i tested it) static public bool CheckExist(string url) { HttpWebRequest wreq = null; HttpWebResponse wresp =...

Why is this WebRequest code slow?

I requested 100 pages that all 404. I wrote { var s = DateTime.Now; for(int i=0; i < 100;i++) DL.CheckExist("http://google.com/lol" + i.ToString() + ".jpg"); var e = DateTime.Now; var d = e-s; d=d; Console.WriteLine(d); } static public bool CheckExist(string url) { HttpWebRequest wreq...

Reading custom HttpWebResponse StatusDescription?

I'm setting a custom StatusDescription in a RESTful WCF service when an exception is thrown. It's meant to provide the caller with a friendly description of why they got the failure status code. The following is the response I see in Fiddler. So I know that my custom message is getting pushed back through to the caller. What I can't ...

Optimal buffer size for response stream of HttpWebResponse

What's the optimal buffer size to use with a stream from HttpWebResponse.GetResponseStream()? Online examples vary from 256b to as much as 5Kb. What gives? I guess buffer sizes might be situational. If so what are the situations to use what type of buffer size? Thanks. ...

Not generating a complete response from a HttpWebResponse object in C#

I am creating a HttpWebRequest object from another aspx page to save the response stream to my data store. The Url I am using to create the HttpWebRequest object has querystring to render the correct output. When I browse to the page using any old browser it renders correctly. When I try to retrieve the output stream using the HttpWeb...

HttpWebRequest and SSL in .NET CF 3.5

We're making some calls to some very simple JSON web services in .NET CF 3.5 / Windows Mobile 6 and it appears that we've run into this bug: http://blogs.msdn.com/andrewarnottms/archive/2007/11/19/why-net-compact-framework-fails-to-call-some-https-web-servers.aspx Is it really almost two years later and this isn't fixed? Seems like a pr...

What byte[] concludes a HTTP server response?

what byte/bytes do you send to conclude a HTTP server response? ...

C# HTTPWebResponse + StreamReader Very Slow!!!

Hi all. I'm trying to implement a limited web crawler in C# (for a few hundred sites only) using HttpWebResponse.GetResponse() and Streamreader.ReadToEnd() , also tried using StreamReader.Read() and a loop to build my HTML string. I'm only downloading pages which are about 5-10K. It's all very slow! For example, the average GetRespons...

How to submit a form automatically using HttpWebResponse

I am looking for an application that can do the following a) Programmatically auto login to a page(login.asxp) using HttpWebResponse by using already specified username and password. b) Detect the redirect URL if the login is successful. c) Submit another form (settings.aspx) to update certain fields in the database. The required co...

Using HttpWebRequest to download html pages returns ContentLength as -1

Hi, I'm trying to get a bunch of HTML files downloaded from the internet and using HttpWebRequest to do it. However when I use WebRequest.Create("http://www.stackoverflow.com/"); WebRequest.GetResponse(); The HttpWebResponse.ContentLength is always -1. I have to show the progress of these pages downloading, in our existing VB6 versi...

Uses of content-disposition in an HTTP response header

I have found the following asp.net code to be very useful when serving files from a database: Response.AppendHeader("content-disposition", "attachment; filename=" + fileName); This lets the user save the file to their computer and then decide how to use it, instead of the browser trying to use the file. What other things can be done ...

Is there an enum for the ContentType property on a HttpWebResponse ("text/plain", "application/octet-stream" etc.)?

The closest thing I could find was System.Net.Mime.MediaTypeNames but that doesn't seem to have everything (like json) since it seems to be more focused around email attachments. ...

HttpWebRequest and HttpWebResponse : maintaining state of logged in request for consecutive queries

Hi, I have a few HttpWebRequests and HttpWebResponses chained together, also using CookieContainer. The code simulates a user going through three different 'I agree' pages which set the cookie info, logging in with username and password on a fourth, and doing a POST (search) on the fifth returning the response as a string. Is there a ...

How to determine Session Timeout using when reusing CookieContainer

I have the following code which re-uses a CookieContainer which logs in on the first request, but just uses the cookie container for requests after. After a period of time if idle the site will give a Session Timeout, I will need to perform the login again. Q: Can I determine (with the cookie container object) if the timeout has happen...

Strange Timeout WebException in HTTP Get using WebClient

Hi, I have a multi-thread application (in c#) that it does multiples HTTP GET to uri. Suddenly after of thousand of requests, i get timeout webException but destination server is OK if i test using browser. The code is: public static string Get(string uri) { string responseData = string.Empty; using (WebClient wc = new WebClien...