locked
Get rid of Connection header in HttpWebRequest

    Question

  • I would like to omit the Connection header entirely from an HTTP request. I cannot for the life of me figure out how.

    The documentation says to set the Connection property to a null reference in order to clear it, but when I do I get an ArgumentException "This header must be modified using the appropriate property.\r\nParameter name: name"
    Call Stack:
    System.dll!System.Net.WebHeaderCollection.ThrowOnRestrictedHeader(string headerName) + 0x15f bytes    
    System.dll!System.Net.WebHeaderCollection.Remove(string name) + 0x2f bytes    
    System.dll!System.Net.HttpWebRequest.Connection.set(string value) + 0x35 bytes

    Relevant code:

    WebResponse objResponse; 
    HttpWebRequest objRequest = (HttpWebRequest) WebRequest.Create(url); 
    objRequest.KeepAlive = false//tried true, false, and omitting, same problem 
    objRequest.Connection = null//<--Exception 
    objResponse = objRequest.GetResponse(); 

    Thanks for any help,
    --Max

     

    Edit: I'm using VS2005, .NET framework 2.0

    • Moved by nobugzMVP Friday, January 23, 2009 12:15 AM not a bcl q (Moved from .NET Base Class Library to Network Class Library (System.Net))
    Thursday, January 22, 2009 11:39 PM

Answers

All replies