0

I have the following php code which acts as proxy to my http server

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 (")");
    ?>

The webservice hosted on IIS has the following contract

   [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); 

From the browser I am trying to call the uri as

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

However the request is failing with the following message

>

 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
> )

. I think I am not passing the arguments correctly

sameer karjatkar
  • 2,017
  • 4
  • 23
  • 43

2 Answers2

1

You aren't setting a parameter called 'callback' and so it isn't set in the $_GET variables.

You could fix the error message by doing:

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

and add a '&' in the url:

echo(file_get_contents($url . '/' . $_GET["poolingServer"] . '&' . $_GET["serverPID"]))
Edi G.
  • 2,432
  • 7
  • 24
  • 33
  • Now its reporting Warning: file_get_contents(http://xomw764dei/IPDWSRest/Service1.svc/getServerUtil/thunderw7dei&23456'): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in C:\Users\xom\Documents\My Web Sites\EmptySite2\slavePerf.php on line 8 – sameer karjatkar Sep 11 '14 at 09:40
  • Is my uri template in the webservice correct UriTemplate = "getServerUtil/{poolingServer}&{serverPID}" – sameer karjatkar Sep 11 '14 at 09:41
  • http://stackoverflow.com/questions/8482782/file-get-contents-throws-400-bad-request-error-php – Edi G. Sep 11 '14 at 09:48
  • The php response is file_get_contents(http://xomw764dei/IPDWSRest/Service1.svc/getServerUtil/thunderw7dei&ABC): failed to open stream: HTTP request failed! for the url http://localhost:1136/slavePerf.php?poolingServer=thunderw7dei&serverPID=ABC – sameer karjatkar Sep 11 '14 at 11:21
1

The problem was resolved when I modified my php file for file_get_contents

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

and my uriTemplate to

[WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "getServerUtil/{poolingServer}/{serverPID}", ResponseFormat = WebMessageFormat.Json, Method = "GET")]
sameer karjatkar
  • 2,017
  • 4
  • 23
  • 43