2014-09-11 63 views
0

我有以下的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 
>) 

失敗?。我認爲我沒有正確傳遞參數

+0

「但是請求失敗」 - > Errormessage? – 2014-09-11 09:20:42

+1

@EdiG。我已更新錯誤消息 – 2014-09-11 09:23:02

+1

您的請求部分中是否有URL中的參數'callback'? – 2014-09-11 09:30:35

回答

1

當我修改我的PHP文件的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")] 
1

您沒有設置一個名爲'callback'的參數,所以它沒有在$ _GET變量中設置。

你可以做修復的錯誤信息:

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

,並添加「&」的網址:

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

現在報告 警告:file_get_contents(http://xomw764dei/IPDWSRest/Service1.svc/getServerUtil/thunderw7dei&23456'):無法打開流:HTTP請求失敗! HTTP/1.1 400錯誤的請求在C:\ Users \ xom \ Documents \ My Web Sites \ EmptySite2 \ slavePerf.php在線8 – 2014-09-11 09:40:16

+0

我的uri模板在webservice中正確 UriTemplate =「getServerUtil/{poolingServer}&{serverPID} 「 – 2014-09-11 09:41:26

+0

http://stackoverflow.com/questions/8482782/file-get-contents-throws-400-bad-request-error-php – 2014-09-11 09:48:05