ERROR: This header must be modified using the appropriate property. Parameter name: name

Posted on 2008-11-05
Last Modified: 2011-10-19
"This header must be modified using the appropriate property. Parameter name: name"

I get the error above when trying to pass the headers from one XML over HTTP post to another.  I've attached the error screenshot as well as my code.  I works fine on the response - but just not on the request.  How can I accomplish this?  The basic purpose of this code is to receive an XML over HTTP post from the first server, read the XML, store it into a database and then repost the EXACT same XML (headers included) to a third server so that the third server gets the exact same XML post that the first server sent.

Current Process:

New Process:
SERVER1 ===XML===> SERVER2 (store XML data) ===XML===> SERVER3

Public Function PostXml(ByVal url As String, ByVal xml As String, ByVal headers As NameValueCollection, ByRef ReturnHeaders As NameValueCollection, ByRef ReturnStatusCode As Integer) As String

        Dim returnValue As String = ""



        Dim bytes As Byte() = Encoding.UTF8.GetBytes(xml)

        Dim request As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)

        request.Method = "POST"

        request.ContentLength = bytes.Length

        request.ContentType = "text/xml"




        Call WriteToFile(SendFile & "Headers.txt", request.Headers.ToString())


        Using requestStream As Stream = request.GetRequestStream()

            requestStream.Write(bytes, 0, bytes.Length)

        End Using


        Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)


        If response.StatusCode <> HttpStatusCode.OK Then

            Dim message As String = [String].Format("POST failed. Received HTTP {0}", response.StatusCode)

            Throw New ApplicationException(message)

        End If

        Dim rs As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)

        Dim receiveStream As Stream = rs.GetResponseStream()

        Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")

        Dim readStream As New StreamReader(receiveStream, encode)


        Dim read(256) As [Char]

        Dim count As Integer = readStream.Read(read, 0, 256)

        While count > 0

            Dim str As New [String](read, 0, count)

            returnValue += str

            count = readStream.Read(read, 0, 256)

        End While

        ReturnStatusCode = rs.StatusCode

        ReturnHeaders = rs.Headers




        'Catch ex As Exception

        'Return ex.Message

        'End Try

        Return returnValue

    End Function

Open in new window

Question by:edenmachine
    LVL 6

    Expert Comment

    You could try adding the headers in a loop (note the code below is just pseudo code)
    For each item in headers
    request.headers(item.key) = item.value
    next item
    LVL 1

    Author Comment

    Yes, I've tried that as well.  I get the same error when I do it that way as well.
    LVL 1

    Accepted Solution

    Hmm - apparently you can't just take the old headers and through them into the new heards (I assume because some are read-only) so once I just added the ones I knew I needed, it worked fine.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
    This video is a brief demonstration on how to use security groups and Network Access Control Lists (ACLs) in Amazon Web Services.  Security groups and Network ACLs are mechanisms you can use in AWS to control network traffic.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now