1
votes

I'm trying to connect via PHP to the smartystreets API (liveaddress) on an IIS web server. I copied both the file_get_contents and cURL examples from here: SmartyStreets github PHP examples. Neither of them work. If I paste the URL directly into my browser, it does work. The file_get_contents example returns:

Warning: file_get_contents(https://api.qualifiedaddress.com/street-address/?street=817+Quail+Ln.+%2312+bakersfield%2C+ca+93309&auth-token=5Nk1%2FA) [function.file-get-contents]: failed to open stream: No such file or directory in C:\Inetpub\includes\myclass.php on line 28

I have confirmed in phpinfo that allow_url_fopen is on. I've also tried setting a user_agent. Still, this doesn't work.

The cURL example returns false.

Could this be something with IIS? Or perhaps due to a firewall setting? If so, how do I find out what port to open? Are there any other possibilities? Thank you!

3
I answered my own question below (it was an issue with ssl being used in the api), but Paul answered it better than me. If you're having a similar problem, you might want to read both to get the full path I took to solve it.dallin

3 Answers

3
votes

Try this. Usually it is enough to get SSL to work with cURL (it is some kind of min./default/simple/widespread ;) configuration of SSL used for APIs), but anyway it depends on the provider SSL configuration.

curl_setopt($ch, CURLOPT_SSLVERSION, 3); // OpenSSL issue
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);  // Wildcard certificate
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

If it won't work, try to know smth. about SSL configuration of your provider and you will definitely find a solution.

0
votes

That webservice requires authorization.

See curl_setopt manual for details how to pass authentication details.

0
votes

I finally got cURL working. The issue was that the link is using SSL (the https in the url). I discovered this by echoing curl_error($ch); I added this one cURL option and it worked perfectly:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

I'm not sure if the reason file_get_contents didn't work was related to this or not.