【问题标题】:https php request - Not returning any datahttps php 请求 - 不返回任何数据
【发布时间】:2017-03-07 04:37:45
【问题描述】:

我尝试使用 php 访问 URL“https://nutraplanet.com”,而我没有从任何请求方法获取数据。请求您给我一些解决方案。

请在下面找到我的代码之一:

<?php
$output= file_get_contents('https://nutraplanet.com/products/controlled-labs-orange-triad/');
echo $output;
?>

即使 CURL 也没有帮助我。请给我同样的建议。

提前致谢。

【问题讨论】:

  • 感谢您及时回复此 Franz。但是,我已经尝试过导致我失败的链接。
  • 能否提供您遇到的任何错误消息以及您尝试过的其他代码?
  • 嘿,你可以使用我已经完成的简单 $.ajax 请求来做到这一点,这只是你需要特定文件的内容是的
  • 当然,它没有给我任何错误,而是给了我一个空的响应。这是我的另一个代码。 nutraplanet.com/products/controlled-labs-orange-triad'; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $result = curl_exec($ch); curl_close($ch);回显$结果; ?>

标签: php curl https file-get-contents


【解决方案1】:

首先您必须启用此扩展程序 https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en 在您的浏览器中

试试这段代码

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<body>

<button id="getData">Get Attendees</button>
<div id="div1">
</div>

</body>

<script type="text/javascript">

$("#getData").click(function(){
    var name = $("#eventid").val();
    $.ajax({url: "https://nutraplanet.com/products/controlled-labs-orange-triad",
        method:"get",
         success: function(result){
        $("#div1").html(result);
    }});
});
</script>

【讨论】:

  • Jaydip,我正在尝试在 Rackspace 服务器上执行代码。那么,程序应该是怎样的呢?
  • 你可以在本地服务器上试试
  • 将上面的代码粘贴到body标签之间,并启用上面的扩展名
猜你喜欢
  • 1970-01-01
  • 2021-07-07
  • 2012-04-04
  • 1970-01-01
  • 1970-01-01
  • 2014-02-12
  • 2021-11-19
  • 1970-01-01
  • 2021-03-25
相关资源
最近更新 更多