I'm trying to use the web request class in vb.net to post some xml. On the reciving end, I keep getting an internal server error with the message: Missing Soap action header". I did some reasearch and saw that a firewall can strip out the soap action header so I tried running it with no firewall and got the same result. I tried adding a soap action header using the header command, and that didn't even get to the server to receive an error message. Can anyone tell me how to add the soap action header? Code is below:
Public Sub PostToWebsite(ByVal sData As String)
Dim oRequest As WebRequest = WebRequest.Create(cDestinationURL)
oRequest.Method = "POST"
'convert data to a byte array
Dim bArray As Byte() = Encoding.UTF8.GetBytes(sData)
'set content type
oRequest.ContentType = "application/x-www-form-urlencoded"
' soap action (this is the header I tried to add. Didn't work.)
' oRequest.Headers.Add("SOAPAction", "\ \ ")
' Set the ContentLength property of the WebRequest.
oRequest.ContentLength = bArray.Length
' Get the request stream.
Dim dataStream As Stream = oRequest.GetRequestStream
Try
' Write the data to the request stream.
dataStream.Write(bArray, 0, bArray.Length)
Catch ex As Exception
cPostResponse = "Error Sending Data: " & ex.Message
Exit Sub
End Try
' Close the Stream object.
dataStream.Close()
Try
' Get the response.
Dim oResponse As WebResponse = oRequest.GetResponse()
dataStream = oResponse.GetResponseStream()
Catch ex As Exception
cPostResponse = "Error Getting Response: " & ex.Message
Exit Sub
End Try
' Get the stream containing content returned by the server.
' Open the stream using a StreamReader for easy access.
Dim oReader As New StreamReader(dataStream)
' Read the content.
cPostResponse = oReader.ReadToEnd()
' Clean up the streams.
oReader.Close()
dataStream.Close()
End Sub