我正在尝试使用UPS API验证带有City的zipCode " https://www.ups.com/ups.app/xml/AV"
以下是我的代码
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();
它在我的本地计算机上运行正常。但是当我在实时服务器上部署它时。它给出了错误 基础连接已关闭:接收时发生意外错误._____ 在System.Net.HttpWebRequest.GetRequestStream(TransportContext&amp; context) 在System.Net.HttpWebRequest.GetRequestStream()
我尝试将ServicePointManager.SecurityProtocol设置为TLS,TLS11或TLS12 但没有什么工作在实时服务器上。 还尝试了request.KeepAlive = false,request.UseDefaultCredentials = true 和request.UserAgent to&#34;任何大于5 char&#34;。
的单词服务器正在运行Windows Server数据中心SP2 我们将不胜感激。 感谢
答案 0 :(得分:0)
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
.net默认情况下会选择服务器中存在的最高安全协议