[Last Call] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2008-11-05
Medium Priority
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
  • 2

Expert Comment

ID: 22886950
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

Author Comment

ID: 22887173
Yes, I've tried that as well.  I get the same error when I do it that way as well.

Accepted Solution

edenmachine earned 0 total points
ID: 22891249
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.

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These instructions are based on installing Owncloud on your new raspberry pi connected with a usb HDD. What do you need Part A? A Raspberry Pi, model B. A boot SD card for the Raspberry Pi. A usb HDD An Ethernet cable to connect to the lo…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

834 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