【问题标题】:Unable to pass multiple arguments in php $_GET无法在 php $_GET 中传递多个参数
【发布时间】:2014-11-05 04:14:35
【问题描述】:

我有以下 php 代码作为我的 http 服务器的代理

slavePref.php

<?php
    $url = 'http://xyzdei/IPDWSRest/Service1.svc/getServerUtil';

    $callback = $_GET["callback"];
    echo($callback . "(");
    header('Content-Type: application/json; charset=utf8');
    echo(file_get_contents($url . '/' . $_GET["poolingServer"], $_GET["serverPID"]));

    echo (")");
    ?>

在 IIS 上托管的 web 服务具有以下合同

   [OperationContract]
        [FaultContract(typeof(ExceptionOnIPDWS))]
        [WebInvoke(BodyStyle = WebMessageBodyStyle.WrappedRequest, UriTemplate = "getServerUtil/{poolingServer}&{serverPID}", ResponseFormat = WebMessageFormat.Json, Method = "GET")]
        //Status getServerUtil(string poolingServer,string serverPID, ref string oCreateResult); 
        string getServerUtil(string poolingServer, string serverPID); 

在浏览器中我试图将 uri 称为

http://:1136/slavePerf.php?poolingServer=thunderw7dei&serverPID=23456

但是请求失败并显示以下消息

>

 Notice: Undefined index: callback in C:\Users\xom\Documents\My Web
> Sites\EmptySite2\slavePerf.php on line 4  ( Warning:
> file_get_contents(http://xomw764dei/IPDWSRest/Service1.svc/getServerUtil/thunderw7dei):
> failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in
> C:\Users\xom\Documents\My Web Sites\EmptySite2\slavePerf.php on line 8
> )

。我认为我没有正确传递参数

【问题讨论】:

  • “但是请求失败” -> 错误消息?
  • @EdiG。我已经更新了错误信息
  • 您的 URL 请求部分中是否有参数 callback
  • @sameerkarjatkar 那么URL中没有回调参数的问题,您正在尝试获取不存在的参数值
  • 测试:带有 echo $url 的 url。 '/' 。 $_GET["poolingServer"] 。 '&' 。 $_GET["serverPID"];

标签: c# php iis


【解决方案1】:

您没有设置一个名为“回调”的参数,因此它没有在 $_GET 变量中设置。

您可以通过以下方式修复错误消息:

$callback = "";
if(array_key_exists('callback', $_GET) == TRUE){
    $callback = $_GET['callback'];
}

并在网址中添加一个“&”:

echo(file_get_contents($url . '/' . $_GET["poolingServer"] . '&' . $_GET["serverPID"]))

【讨论】:

【解决方案2】:

当我为 file_get_contents 修改我的 php 文件时,问题已解决

echo(file_get_contents($url . '/' . $_GET["poolingServer"]));

和我的uriTemplate

[WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "getServerUtil/{poolingServer}/{serverPID}", ResponseFormat = WebMessageFormat.Json, Method = "GET")]

【讨论】:

    猜你喜欢
    • 2019-06-10
    • 2023-04-07
    • 2011-03-14
    • 2019-10-06
    • 1970-01-01
    • 1970-01-01
    • 2011-04-20
    • 2014-07-17
    • 2011-11-04
    相关资源
    最近更新 更多