2016-12-19 42 views
1

我有一个发布请求php代码,我用它来获取流式URL,所以我可以将它们广播给我的访问者。 显然,我使用的其他订阅服务具有更强的安全性,并且它要求仅从您首先发送请求才能获取该流式URL的IP访问流式URL。向访问者网络发送帖子请求?可能?

因此,当用户打开channel1.php实际POST请求是从他的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]; 
?> 

回答

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您发布后的东西它。 我只知道如何发送它。