【问题标题】:PHP QueryString 404 Object Not FoundPHP QueryString 404 对象未找到
【发布时间】:2013-02-07 07:55:15
【问题描述】:

我是一名 Android 开发人员,对 PHP 知之甚少。从查询字符串中读取变量时,我遇到了获取 404 Error Object Not Found 的问题。我添加了 .htaccess 文件,结果错误确实消失了,但变量没有被读取。虽然如果我读取没有查询字符串的 URL,它会完美运行。我想不出它不应该工作的原因。这是我尝试过的:

PHP 文件:

文件名:file_getTest.php

function file_get_contents_curl($url) {
  $ch = curl_init();
  $timeout = 5;
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  $data = curl_exec($ch);
  curl_close($ch);
  return $data;
}
$baseUrl='http://xyz.com?language=en';
$language = $_GET['language'];
$session = $_GET['sessionID'];
$placeOrigin=$_GET['place_origin'];
$typeOrigin=$_GET['type_origin']; 
$nameOrigin=$_GET['name_origin'];
$homePage =($baseUrl."&sessionID=".$session."&place_origin=".$placeOrigin."&type_origin=".$typeOrigin."&name_origin=".$nameOrigin);

//if "echo file_get_contents($baseUrl)" is executed it works fine

//echo file_get_contents($homePage); //I have tried file_get_contents but no use

echo file_get_contents_curl($homePage);

.ht访问代码:

RewriteEngine on
RewriteRule .* file_getTest.php

没有 .htacess 文件并使用 curl() 我收到此错误:

请求的 URL /test/file_getTest.php&sessionID=读取值&place_origin=读取值&type_origin=读取值&name_origin=读取值在此服务器上未找到读取

使用 .htaccess 文件并使用 curl() 我收到以下错误:

HTTP/1.1 404 未找到对象

没有 .htacess 文件并使用 file_get_contents() 我收到此错误:

请求的 URL /test/file_getTest.php&sessionID=读取值&place_origin=读取值&type_origin=读取值&name_origin=读取值在此服务器上未找到读取

使用 .htaccess 文件并使用 file_get_contents() 我收到以下错误:

file_get_contents(http://xyz.com?language=en&sessionID=&place_origin=&type_origin=&name_origin=):打开流失败:HTTP 请求失败! HTTP/1.1 404 Object Not Found in C:\wamp\www\file_getTest.php on line 20

我将非常感谢任何帮助。我已经在这个问题上停留了一段时间,似乎无法找到解决方案。

【问题讨论】:

  • 这就是我被卡住的原因。我似乎找不到错误,但感谢您的意见。
  • 框架 URL 是否在 Web 浏览器中独立工作?不过,您需要验证那些 $_GET 参数。
  • 是的,该 URL 工作正常。包括查询字符串中的参数没有任何问题
  • 你能从 PHP 访问说 google.com 吗?然后检查配置。
  • 是的,工作得很好。我在访问静态 URL 时没有问题我在获取参数时遇到问题。

标签: php curl query-string file-get-contents


【解决方案1】:

问题已解决。这看起来很奇怪,但我所做的只是将 $homepage 中的双引号 "" 与其余变量中的单引号交换。之后,我对所有查询字符串参数进行了编码,它就像一个魅力。

所以最终代码如下所示:

$baseUrl="http://xyz.com?language=en";

$session = $_GET["sessionID"];
$placeOrigin=$_GET["place_origin"];
$typeOrigin=$_GET["type_origin"]; 
$nameOrigin=$_GET["name_origin"];

$placeDestination=$_GET["place_destination"];
$typeDestination=$_GET["type_destination"];
$nameDestination=$_GET["name_destination"];

$sessionE=urlencode($session);
$placeOriginE=urlencode($placeOrigin);
$typeOriginE=urlencode($typeOrigin);
$nameOriginE=urlencode($nameOrigin);

$placeDestinationE=urlencode($placeDestination);
$typeDestinationE=urlencode($typeDestination);
$nameDestinationE=urlencode($nameDestination);

$homepage=$baseUrl.'&sessionID='.$sessionE.'&place_origin='.$placeOriginE.'&type_origin='.$typeOriginE.'&name_origin='.$nameOriginE.'&place_destination='.$placeDestinationE.'&type_destination='.$typeDestinationE.'&name_destination='.$nameDestinationE;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-05
    • 1970-01-01
    • 2015-12-17
    • 1970-01-01
    • 2017-06-27
    • 2013-04-21
    相关资源
    最近更新 更多