I am trying to validate the zipCode with City using UPS API "https://www.ups.com/ups.app/xml/AV".
Below is my code
string xmlRequest = "<?xml version=\"1.0\"?>" +
"<AccessRequest>" +
"<AccessLicenseNumber>xxxx</AccessLicenseNumber>" +
"<UserId>xxx</UserId>" +
"<Password>xxx</Password>" +
"</AccessRequest>" +
"<?xml version=\"1.0\"?>" +
"<AddressValidationRequest xml:lang=\"en-US\">" +
"<Request>" +
"<TransactionReference>" +
"<CustomerContext>Customer Data</CustomerContext>" +
"<XpciVersion>1.0001</XpciVersion>" +
"</TransactionReference>" +
"<RequestAction>AV</RequestAction>" +
"</Request>" +
"<Address>" +
"<PostalCode>" + "38305" + "</PostalCode>" +
"<City>" + "TENNESSEE" + "</City>" +
"</Address>" +
"</AddressValidationRequest>";
string url = "https://www.ups.com/ups.app/xml/AV";
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
//ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
byte[] requestBytes = System.Text.Encoding.ASCII.GetBytes(xmlRequest);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencode";
req.ContentLength = requestBytes.Length;
// req.KeepAlive = false;
//req.UseDefaultCredentials = true;
// req.UserAgent = "Patoooey";
Stream requestStream = req.GetRequestStream();
requestStream.Write(requestBytes, 0, requestBytes.Length);
requestStream.Close();
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.Default);
string backstr = sr.ReadToEnd();
It works fine on my local machine. but when i deploy it on live server. it gives error The underlying connection was closed: An unexpected error occurred on a receive._____ at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context) at System.Net.HttpWebRequest.GetRequestStream()
I have tried setting ServicePointManager.SecurityProtocol to TLS, TLS11 or TLS12 but nothing is working on live server. Also tried request.KeepAlive = false, request.UseDefaultCredentials = true and request.UserAgent to "any word greater than 5 char".
Server is running Windows Server Data Center SP2 Your help will be appreciated. Thanks