跨域访问 USPS 地址验证 API

Cross Domain access to USPS Address validation API

我正在尝试通过 AJAX 调用来验证 USPS 地址验证 API,但出现 'Cross-Origin Request Blocked' 错误。

然而,当我尝试通过 URL 访问同一地址时,我得到了结果。

这个错误与审批有关吗?

我为此使用的 ID 已获批准,我可以通过 API 到 URL 获得结果。

我想通过脚本访问它。请帮忙。

如有任何帮助,我们将不胜感激。

提前致谢。

我认为您可能想要执行此操作的方法是将 Ajax 请求发送到您的网络服务器——页面来自的同一 HTTP 服务器。然后您的 server-side 程序(在 PHP 或 Python 或您正在使用的任何程序中) 将请求中继到 USPS 服务器

从 Ajax 直接向 USPS 服务器发出请求 browser-side,正是浏览器正在学习的那种可疑 activity(称为 Cross-Site 脚本)阻止。

CORS could theoretically be one way to unblock a Cross-Origin Request, but in that scheme it would be the USPS API server that ultimately grants that permission for pages from your domain. Tech detail:通过插入 Access-Control-Allow-Origin header 来响应 Ajax Origin header 中的请求 back-and-forth.