doucheng4660 2013-04-29 16:05
浏览 59
已采纳

有角度的括号在PHP中从URL中转义

I am trying to call the USPS API that takes in the zip code and returns XML containing the City Name of the given zip code.

Here is the URL they require:

http://production.shippingapis.com/ShippingAPITest.dll?API=CityStateLookup 
&XML=<CityStateLookupRequest USERID="xxxxxxx"><ZipCode ID= "0"> 
<Zip5>90210</Zip5></ZipCode></CityStateLookupRequest> 

In my PHP file, when I echo out the above URL, this is what I get:

http://production.shippingapis.com/ShippingAPITest.dll?API=CityStateLookup&XML=90007

All the XML part of the URL is missing. I need to get curl data from the URL.

Anyone know what I could be missing?

  • 写回答

2条回答 默认 最新

  • dougu0824 2013-04-29 16:07
    关注

    Anyone know what I could be missing?

    Probably. Maybe, yes. What you describe in your posting sounds like an encoding problem. So you are missing the right encoding.

    As you are talking about an URL that is likely URL encoding. Some characters - like space - have a special meaning inside an URL so you can not just use any character as you like, but you need to encode all characters properly.

    The exact description how you need to formulate an URL incl. the exact description how URL encoding works is outlined in 2. Characters in the internet standard RFC3986.

    PHP functions related to URL encoding are urlencode() and rawurlencode and more likely useful in your case http_build_query().

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部