Я получаю сообщение об ошибке в HttpWebRequest.GetRequest () при попытке отправить XML-запрос на один веб-сервис для ответа. Этот же запрос работает от Почтальона. Пожалуйста, направьте в правильном направлении, чтобы решить эту проблему. Ниже приведен основной текст и код XML.
string xmlMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
"<soap:Body>"
"<GetDetail xmlns=\"http://tempuri.org/\">"
"<strNo>22101</strNo> <baCode></baCode> <authkey>xxxx</authkey><source>xxxx</source>"
"</GetDetail>" "</soap:Body>" "</soap:Envelope>";
byte[] requestInFormOfBytes = System.Text.Encoding.ASCII.GetBytes(xmlMessage);
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("https://xxxxxxx.xx/xxxx/GetDetail");
webRequest.Method = "POST";
webRequest.ContentType = "application/xml";
webRequest.Headers.Add("SOAPAction", "http://tempuri.org/GetDetail");
webRequest.Headers.Add("Client-Id", "XXXXXXXXXXXXX");
webRequest.Headers.Add("Client-Secret", "XXXXXXXXXXXXXXXXX");
webRequest.Accept = "application/xml";
webRequest.ContentLength = requestInFormOfBytes.Length;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
Ошибка в этой строке.
Поток requestStream = webRequest.GetRequestStream ();
requestStream.Write(requestInFormOfBytes, 0, requestInFormOfBytes.Length);
requestStream.Close();
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
StreamReader respStream = new StreamReader(response.GetResponseStream(), System.Text.Encoding.Default);
string receivedResponse = respStream.ReadToEnd();
Console.WriteLine(receivedResponse);
respStream.Close();
response.Close();
Спасибо всем за правильное направление, оно решено с помощью (1) Test with FrameWork 4.6
(2) Используйте SecurityProtocoltype.Tls12 (см. - https://stackoverflow.com/a/32789483/5694613).