USPS API 返回 501 未实现
我正在尝试利用 USPS API 进行一些地址验证/确认。
我将此 XML 发送到 http://testing.shippingapis.com/ShippingAPITest.dll :
<AddressValidateRequest%20USERID="xxxxx"><Address ID="0"><Address1></Address1><Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>MD</State><Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>
这与测试请求文档中显示的 XML 相同。但是,我总是收到 HTML(而不是 XML)响应,该响应是 501 Not Implmented 错误。熟悉这个 API 的人知道会发生什么吗? 请求
我正在使用curl(在php中)来发出更新 :当我通过在带有 get params 的浏览器中输入 url 来发出请求时,它似乎工作正常,但我使用 php/curl 或仅从命令行中使用curl 收到上述错误。
更新:如果我使用 file_get_contents 和 url,我会收到 400 bad request 错误 - 但如果我 urlencode,它效果很好 - 解决方案被接受。
I am attempting to utilize the USPS API to do some address verification/validation.
I'm sending this XML to http://testing.shippingapis.com/ShippingAPITest.dll:
<AddressValidateRequest%20USERID="xxxxx"><Address ID="0"><Address1></Address1><Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>MD</State><Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>
This is the same XML that is shown in their documentation for test requests. However, I always get an HTML (instead of XML) response that is a 501 Not Implmented error. Anyone familiar with this API know what might be going on? I'm using curl (in php) to make the request
UPDATE: When I make the request by typing the url into a browser with get params, it seems to work fine, but i get the error mentioned above using php/curl or just curl from the command line.
UPDATE: If I use file_get_contents with the url, I get a 400 bad request error - but if i urlencode, it works great - solution accepted.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不熟悉API,但是:
您需要
AddressValidateRequest
后面的%20
吗?当它被替换为空格时它起作用吗?另外,需要使用CURL吗?您可以只使用
fopen()
或file_get_contents()
然后使用您提到的 GET 参数吗?Not familiar with the API, but:
Do you need the
%20
afterAddressValidateRequest
? Does it work when that is replaced by a space?Also, do you need to use CURL? Could you just use
fopen()
orfile_get_contents()
and then use the GET parameters which you mention work OK?