发送访问者网络的发布请求?可能的



我有一个帖子请求php代码,用于获取流媒体URL,以便我可以向访问者广播它们。显然,我使用的其他订阅服务具有更强的安全性,它要求仅从您首先从您发送请求的IP访问流url以获取流媒体URL。

因此,当用户打开Channel1.php时,我需要从他的IP地址发送请求(而不是我的服务器),以便他可以观看流。可能?

这是代码

<?php
$params = array ('password' => 'mypassword', 'username' => 'mysecretusername');
$query = http_build_query ($params);
$contextData = array ( 
            'method' => 'POST',
            'header' => "Connection: closern".
                        "Content-Length: ".strlen($query)."rn"."User-Agent: okhttp/2.5.0",
            'content'=> $query );
$context = stream_context_create (array ( 'http' => $contextData ));
$result =  file_get_contents (
              'http://api.source.stream/streams/1/sign',  // page url
              false,
              $context);
$json = json_decode($result, true);
$pink = $json[url];
echo $json[url];
?>

也许您想尝试这样的东西

<script>
// Sending and receiving data in JSON format using POST mothod
//
xhr = new XMLHttpRequest();
var url = "http://your.url.com/streams/1/sign";
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-type", "application/json");
xhr.onreadystatechange = function () { 
    if (xhr.readyState == 4 && xhr.status == 200) {
        var json = JSON.parse(xhr.responseText);
        console.log(json.username + ", " + json.password)
    }
}
var data = JSON.stringify({"username":"YOURUSERHERE","password":"YOURURLHERE"});
xhr.send(data);
</script>

,但是在您发布后,我真的不知道如何从他们的服务器中打印出PHP的答案。我只知道如何发送。

最新更新