No results when using a web API

后端 未结 1 1399
不思量自难忘°
不思量自难忘° 2021-01-16 00:27

I\'m attempting to pull an XML page from the U.S. Postal Service (USPS) rate calculator, using PHP. Here is the code I am using (with my API login and password replaced of

1条回答
  •  花落未央
    2021-01-16 01:26

    One thing is that you need to URL encode the XML that you are sending to the service. The browser will do that for you automatically, but file_get_contents won't.

    Try this:

     $param = urlencode("".
       "FIRST CLASSPARCEL".
       "1234554321".
       "09REGULAR");
    
     $api = "http://production.shippingapis.com/ShippingAPI.dll?API=RateV4&XML="
            .$param;
    
     ... then the rest of the code
    

    If that doesn't help, make sure you have error reporting activated so you get a response if file_get_contents has an error.

    0 讨论(0)
提交回复
热议问题