【问题标题】:Using file_get_contents in php在 php 中使用 file_get_contents
【发布时间】:2013-08-26 06:34:35
【问题描述】:

我尝试使用 php 登录 Geoserver。我愿意:

$geoserverURL = "http://localhost:8080/geoserver/j_acegi_security_check";

$post = http_build_query(array(
        "username" => $username,
        "password" => $password,
));

$context = stream_context_create(array("http"=>array(
    "method" => "POST",
    "header" => "Content-Type: application/x-www-form-urlencoded\r\n" .
            "Content-Length: ". strlen($post) . "\r\n",
    "content" => $post,
)));

$page = file_get_contents($geoserverURL, false, $context);
echo $page;

但在 FireBug 中看不到任何活动。我是 php 新手,所以也许我在这里做错了什么?这个代码片段我被发现here

【问题讨论】:

  • 您似乎对 PHP 是如何执行该代码有误解。在到达任何地方之前,您需要跟踪服务器端代码是什么。 PHP 代码在服务器上运行,而不是在您的浏览器中,因此您不会在 Firebug 中看到任何内容。有关更多信息,请参阅此问题:stackoverflow.com/questions/7407374/…

标签: php post geoserver


【解决方案1】:

您不会在萤火虫中看到它,因为萤火虫会记录您身边(客户端)的事件,这意味着您的浏览器中。如果您使用 ajax,您可以跟踪它,然后 firebug 会记录它

如果您想检查它的轨迹,请使用工具来控制您的网络,例如 WireShark。在那里您将能够记录此请求

如果您需要使用登录名和密码,我建议您使用 cURL。 IMO 好多了

【讨论】:

  • @KliverMax 如果您没有收到任何回复,我猜想是 url、端口或类似的问题。首先,您需要检查您的请求是否指向正确的 url,您是否有任何响应
【解决方案2】:

你可以试试不带端口吗?例如:

$geoserverURL = "http://localhost/geoserver/j_acegi_security_check";

【讨论】:

  • 没有端口我得到错误:Warning: file_get_contents(http://localhost/geoserver/j_acegi_security_check): in D:\xampp\htdocs\rest\index.php on line 64。因此,如果我理解正确,它的意思是使用端口 file_get_contents() 查看请求页面?
猜你喜欢
  • 2014-01-07
  • 1970-01-01
  • 2011-07-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-09
相关资源
最近更新 更多