由于某种原因,此代码不起作用:
$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);
如果我打开浏览器并转到此网址
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 ......就是这样。
答案 0 :(得分:0)
试试这个:
<?php
// helper function
function curlGet($url)
{
// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, $url);
// return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// ssl opts
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
// finished
return $output;
}
// usage
var_dump(curlGet("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\"}"));
?>
答案 1 :(得分:0)
我使用此代码解决了这个问题:
$dataString = urlencode('{"email":"my@email.here","name":"Matthijs de Zwart"}');
$homepage = file_get_contents("https://sendgrid.com/api/newsletter/lists/email/add.json?api_user=myUserName&api_key=myPassword&list=MyList&data[]=".$dataString);
返回我的预期。
答案 2 :(得分:0)
尝试使用他们的apiv3。它用得很好。 但实际上我会寻找新的供应商。在他们将我们锁定在我们的帐户之后,我们离开了他们,他们的48小时支持说“创建一个新帐户”