【问题标题】:Unable to connect to remote server using USPS Web Tools API无法使用 USPS Web Tools API 连接到远程服务器
【发布时间】: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,如果这就是您所说的承诺。

标签: c# webclient usps


【解决方案1】:

对于邮寄地址(在美国),USPS 肯定是权威机构。但是,我从许多同行那里听说他们的 API 有点缺乏。由于 USPS API 不提供 SLA(服务水平协议),因此他们可以随时执行例行或非例行维护。因此,如果您绝对必须使用 USPS API,那么您就会被他们提供给您的任何东西以及他们所拥有的任何停机时间所困。

如果您可以选择考虑其他地址验证 API 服务,请在 Google 上快速搜索“地址验证 API”,您会看到其中一些最好的服务。您的选择范围从免费到非常昂贵。

所以,虽然我无法说明 USPS API 关闭的原因,但希望我能引导您使用更可靠的服务。我听说过easypost.com 的好消息,它是一项免费服务。你也有德州农工大学,它有一个免费的address verification service。因此,无论您找到什么服务,请确保您寻找的服务(免费或付费)实际上具有 SLA 且正常运行时间有保证,可以满足您的需求。

我在 SmartyStreets 工作了将近三年,所以我对地址验证略知一二。

【讨论】:

【解决方案2】:

USPS 网站已关闭!所以他们的服务器可能有问题。

【讨论】:

  • 不确定他们在哪里宣布停电......但这里有一个来源:etsy.com/teams/7716/announcements/discuss/12547306 -- USPS API 没有服务水平协议,并且众所周知会经常出现故障。
  • 如果您遇到麻烦并需要快速验证地址,如果您今天或明天注册并向他们的支持团队发送电子邮件,SmartyStreets 将免费提供 30 天的服务。 smartystreets.com/account/create
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-11-04
  • 2014-06-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多