我有一个帖子请求php代码我用来获取流式网址,以便我可以将它们广播给我的访问者。 显然我使用的其他订阅服务具有更强的安全性,并且它要求仅从您首先发送请求的IP访问流URL以获取该流式URL。
所以我需要当用户打开channel1.php,实际发布请求是从他的IP地址(而不是我的服务器)发送的,这样他就可以观看流。 可能的?
这是代码
<?php
$params = array ('password' => 'mypassword', 'username' => 'mysecretusername');
$query = http_build_query ($params);
$contextData = array (
'method' => 'POST',
'header' => "Connection: close\r\n".
"Content-Length: ".strlen($query)."\r\n"."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];
?>
答案 0 :(得分:1)
也许你想尝试这样的事情
<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的答案。 我只知道如何发送它。