【发布时间】:2013-06-21 03:20:15
【问题描述】:
我目前正在尝试使用United States Postal Service's Web Tools API 来验证用户的地址。但是,无论我使用何种信息组合或技术连接到 Web 服务,我都会遇到相同的异常:
Unable to connect to the remote service
具有相同的内部异常
A connection attempt failed because the connected party did not properly respond after
a period of time, or established connection failed because connected host has failed to
respond 56.0.34.43:443
不过,我是第一次使用 C# WebClient 对象。谁能看到我在这里做错了什么?
private const string USPS_USERID = "xxxxxxx";
private const string BASEURL = "https://secure.shippingapis.com/ShippingAPITest.dll";
try
{
string USPS = BASEURL + "?API=Verify&XML=<AddressValidateRequest USERID=\"" + USPS_USERID + "\">";
USPS += "<Address ID='0'>";
USPS += "<Address1>" + addressInfo[0] + "</Address1>";
USPS += "<Address2>" + addressInfo[1] + "</Address2>";
USPS += "<City>" + addressInfo[2] + "</City>";
USPS += "<State>" + addressInfo[3] + "</State>";
USPS += "<Zip5>" + addressInfo[4] + "</Zip5>";
USPS += "<Zip4></Zip4>";
USPS += "</Address></AddressValidateRequest>";
WebClient wsClient = new WebClient();
byte[] responseData = wsClient.DownloadData(USPS);
string response = string.Empty;
foreach (byte item in responseData)
{
response += (char) item;
}
return Json(response, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
return null;
}
【问题讨论】:
-
您每月进行的地址查找是否少于 250 次?您是否致力于 USPS API?它的维护不是很好。很可能你没有做错任何事。
-
我们可能会,目前只是尝试启动并运行它。我已经向他们注册并收到了我的确认电子邮件和用户 ID,如果这就是您所说的承诺。