【发布时间】:2014-02-12 10:24:55
【问题描述】:
由于某种原因,此代码不起作用:
$url = "https://sendgrid.com/api/newsletter/lists/email/add.json?api_user=myUserName&api_key=myPassword&list=MyList&data[]={\"email\":\"my@email.here\",\"name\":\"Matthijs de Zwart\"}";
$result = file_get_content($url);
$response = json_decode( $result );
var_dump($response);
如果我打开浏览器并转到此 URL
https://sendgrid.com/api/newsletter/lists/email/add.json?api_user=myUserName&api_key=myPassword&list=MyList&data[]={"email":"my@email.here","name":"Matthijs de Zwart"}
我确实得到了回应。
我已经使用了这些检查
echo 'openssl: ', extension_loaded ('openssl') ? 'yes':'no', "\n";
echo 'http wrapper: ', in_array('http', $w) ? 'yes':'no', "\n";
echo 'https wrapper: ', in_array('https', $w) ? 'yes':'no', "\n";
echo 'wrappers: ', var_dump($w);
导致以下输出:
openssl: yes
http wrapper: yes
https wrapper: yes
wrappers: array(22) {
[0]=>
string(13) "compress.zlib"
[1]=>
string(14) "compress.bzip2"
[2]=>
string(4) "dict"
[3]=>
string(3) "ftp"
[4]=>
string(4) "ftps"
[5]=>
string(6) "gopher"
[6]=>
string(4) "http"
[7]=>
string(5) "https"
[8]=>
string(4) "imap"
[9]=>
string(5) "imaps"
[10]=>
string(4) "pop3"
[11]=>
string(5) "pop3s"
[12]=>
string(4) "rtsp"
[13]=>
string(4) "smtp"
[14]=>
string(5) "smtps"
[15]=>
string(6) "telnet"
[16]=>
string(4) "tftp"
[17]=>
string(3) "php"
[18]=>
string(4) "file"
[19]=>
string(4) "glob"
[20]=>
string(4) "data"
[21]=>
string(3) "zip"
}
我一直在谷歌搜索以使其正常工作,但到目前为止,我只能找到说打开 openssl 的解决方案......确实如此。
【问题讨论】:
标签: php json url file-get-contents