0
이 내가 그것을 얻을 및 푸시 알림을 보내려고 쓴 것입니다 :Google Firebase Cloud Messaging Server가 Moved Temporarily를 반환하는 이유는 무엇입니까?
<?php
//send FCM notification
$fcmToken = "My device token";
$fcmKey = "My Firebase Cloud Messaging Server Key";
//I tried curl like this but I barely understand it and it wouldn't work
//curl -X POST --header "Authorization: key=$fcmKey" --Header "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d "{\"to\":\"$fcmToken\",\"notification\":{\"body\":\"Yellow\"},\"priority\":10}"
echo "starting curl <hr>";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://fcm.googleapis.com/fcm/send");
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Authorization: key=$fcmKey","Content-Type: application/json","to: $fcmToken","notification:{\"body\":\"Yellow\"}","priority: 10")); //setting custom header
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
echo "curlResult: " . $result;
curl_close($curl);
echo "<hr>curl end";
?>
나는이 같았다있어 출력, 왜 사전에 어떤 도움?
starting curl <hr>curlResult: <HTML>
<HEAD>
<TITLE>Moved Temporarily</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Moved Temporarily</H1>
The document has moved <A HREF="https://firebase.google.com/docs/cloud-messaging/http-server-ref">here</A>.
</BODY>
</HTML>
<hr>curl end
감사합니다!
리디렉션이 발행되고있는 것 같습니다. 그것은 웹에서 매우 일반적이며 Google이 여기에서 왜 그렇게했는지 추측 할 수있는 이유가 너무 많습니다. Curl이 리디렉션을 따르게하는 방법을 살펴 보시기 바랍니다. http://stackoverflow.com/questions/18474690/is-there-a-way-to-follow-redirects-with-command-line-curl –
예, if 거기에 내 브라우저에 들어가서 https://firebase.google.com/docs/cloud-messaging/http-server-ref에 들어가면 다음과 같이됩니다. curl_setopt ($ curl, CURLOPT_FOLLOWLOCATION, true); 그러나 그것은 틀린 URL이있는 것 같지만 문서가 말하는 것입니다. – Eric
리디렉션은 무언가가 이동했을 때뿐만 아니라 여러 가지 이유로 사용됩니다. 예를 들어 데이터를 웹 사이트에 게시하면 대부분의 웹 사이트가 사용자를 리디렉션합니다. 이렇게하면 브라우저가 정보를 두 번 보내는 것을 막을 수 있습니다. 동일한 경우가 종종 로그인에 해당됩니다. 첫 번째 요청은 사용자 이름과 암호를 보내고 서버는 세션에 대한 쿠키를 제공하면서 다른 페이지로 전달합니다. 브라우저는 다시 "뒤로"를 클릭하더라도 두 번째로 로그인하지 않습니다. –