Google URL Shortener API를 사용하여 응용 프로그램을 만들고 있습니다.PHP에서 curl이 작동하지 않습니다.
MackBook Pro에서 다음 코드는 작동하지만 Windows PC에서는 작동하지 않고 화면에 "NULL"만 표시됩니다.
<?php
// APIkey
$apiKey = '[Here is my API KEY]';
$longUrl = "http://www.absolute-keitarou.net/blog/";
$url1 = 'https://www.googleapis.com/urlshortener/v1/url?key='.$apiKey;
$params = json_encode(array(
"longUrl" => $longUrl
));
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$res = json_decode(curl_exec($curl));
curl_close($curl);
var_dump($res);
?>
MacBook에서 코드는 올바르게 작동하고 다음을 보여줍니다.
개체 (stdClass) {[ "kind"] => 문자열 (16) "urlshortener # url"[ "id"] => 문자열 "http://goo.gl/TMII0"[ "longUrl"] = > string (38) "http://www.absolute-keitarou.net/blog/"
Windows PC에 MacBook과 동일한 출력이 나타나기를 바랍니다. 내가 뭘해야하는지 말해줘. WAMP/빈/PHP/php5.4에서
을 볼 수 있습니다에서 서버의 포트를 변경 'curl_setopt ($ 컬, CURLOPT_SSL_VERIFYPEER, 0);' 도움이되는 것 같습니다. 또한 '$ res'결과를 별도의 단계로 디코딩하십시오. 이렇게하면 응답을 읽을 수 있습니다. –