I am getting an error on HttpWebRequest.GetRequest() when trying to send xml request on one web service for response. This same request working from Postman. Please guide in right direction to solve this. Below is a XML Body text and code.
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;
Error give on this line.
Stream 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();
Thanks for all to give right direction, its resolved by (1) Test with FrameWork 4.6 (2) Use SecurityProtocoltype.Tls12 (refer - https://stackoverflow.com/a/32789483/5694613).