Es para un servidor de sms, yo le envio un xml mediante el post y el me responde con un codigo xml con el resultado.
He realizado una función que utiliza el httpwebrequest y consigo realizar el post sin problemas, pero al intentar acceder a la respuesta utilizando el metodo .getresponse() se produce una excepción "WebException" cuyo status es ServerProtocolViolation.
PD2: La funcion que tengo hecha y produce una excepcion al hacer el .getresponse() es esta (url es la direccion y payload el parametro del post) :
------------------------------------------------------------------------------------------
Public Sub getPage(ByVal url As String, ByVal payload As String)
Dim result As Object
Try
Dim req As HttpWebRequest
Dim RequestStream As Stream
Dim ReceiveStream As Stream
Dim encode As Encoding
Dim sr As StreamReader
Dim alg As Xml.XmlTextReader
req = HttpWebRequest.Create(url)
req.Method = "POST"
req.ContentType = "application/x-www-form-urlencoded"
Dim SomeBytes() As Byte
Dim UrlEncoded As New StringBuilder
Dim reserved() As Char = {ChrW(63), ChrW(61), ChrW(38)}
req.PreAuthenticate = False
req.UnsafeAuthenticatedConnectionSharing = True
req.AllowAutoRedirect = True
If payload <> Nothing Then
Dim i As Integer = 0
Dim j As Integer
While i < payload.Length
j = payload.IndexOfAny(reserved, i)
If j = -1 Then
UrlEncoded.Append(HttpUtility.UrlEncode(payload.Substring(i, payload.Length - i)))
Exit While
End If
UrlEncoded.Append(HttpUtility.UrlEncode(payload.Substring(i, j - i)))
UrlEncoded.Append(payload.Substring(j, 1))
i = j + 1
End While
SomeBytes = System.Text.Encoding.UTF8.GetBytes(UrlEncoded.ToString())
req.ContentLength = SomeBytes.Length
RequestStream = req.GetRequestStream()
RequestStream.Write(SomeBytes, 0, SomeBytes.Length)
RequestStream.Close()
Else
req.ContentLength = 0
End If
'Leyendo respuesta de la web
result = req.GetResponse()
ReceiveStream = result.GetResponseStream()
encode = System.Text.Encoding.GetEncoding("utf-8")
sr = New StreamReader(ReceiveStream, encode)
Dim read(256) As Char
Dim count As Integer = sr.Read(read, 0, 256)
Do While count > 0
Dim str As String = New String(read, 0, count)
Literal1.Text += str
count = sr.Read(read, 0, 256)
Loop
Catch Exc As WebException
Literal1.Text = Exc.Response.ContentLength
Finally
If Not result Is Nothing Then
result.Close()
End If
End Try
End Sub