Я искал и нашел несколько вопросов, касающихся отправки строки xml на URL. Я сравнил с тем, что я использую, и я не могу понять, что происходит. Отправляемая строка xml поступает из текстового поля, поэтому я могу видеть, что отправляется. Это код, который я использую для отправки запроса:
Try
'Dim Request As WebRequest = CType(WebRequest.Create("http://someurl/someasmx.asmx"), WebRequest)
Dim Request As HttpWebRequest = HttpWebRequest.Create("http://someurl/someasmx.asmx")
Dim postdata As String = txtRequest.Text
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postdata)
Request.Method = "POST"
' Set the ContentType property of the WebRequest.
Request.ContentType = "text/xml"
' Set the ContentLength property of the WebRequest.
Request.ContentLength = byteArray.Length
' Get the request stream.
Dim dataStream As Stream = Request.GetRequestStream()
' Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length)
' Close the Stream object.
dataStream.Close()
' Get the response.
'Dim response As WebResponse = Request.GetResponse()
Dim response As HttpWebResponse = Request.GetResponse() <--This is where the error is
' Display the status.
'Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
txtStatusDesc.Text = CType(response, HttpWebResponse).StatusDescription
' Get the stream containing content returned by the server.
dataStream = response.GetResponseStream()
' Open the stream using a StreamReader for easy access.
Dim reader As New StreamReader(dataStream)
' Read the content.
Dim responseFromServer As String = reader.ReadToEnd()
' Display the content.
txtResponse.Text = HttpUtility.HtmlDecode(responseFromServer)
' Clean up the streams.
reader.Close()
dataStream.Close()
response.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
И это XML Я должен отправить
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsd="http:=//www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ProcessRequest xmlns = "http://somewnet.com/WebServices"><XmlRequest><![CDATA[some really long xml string]]></ProcessRequest></soap:Body></soap:Envelope>
И ошибка, которую я получаю:
«Удаленный сервер возвратил ошибку: (400) неверный запрос»
Спасибо!