2016-12-19 47 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您發佈後的東西它。 我只知道如何發送它。