从RPC对象php5.5获取JSON数据
我有一个RPC服务器类,它使用cURL从未指定的给定第三方接受JSON数据 我可以看到数据击中了我的类,我可以将一个var_转储存储到一个似乎是服务器请求的文件中,但是输出看起来像是接收带有入站对象引用的web服务器信息。 但我没有看到我的JSON数据“foo:bar”从RPC对象php5.5获取JSON数据,php,json,curl,rpc,Php,Json,Curl,Rpc,我有一个RPC服务器类,它使用cURL从未指定的给定第三方接受JSON数据 我可以看到数据击中了我的类,我可以将一个var_转储存储到一个似乎是服务器请求的文件中,但是输出看起来像是接收带有入站对象引用的web服务器信息。 但我没有看到我的JSON数据“foo:bar” <?php class jsonRPCServer { public static function handle($object) { if (
<?php
class jsonRPCServer {
public static function handle($object) {
if (
$_SERVER['REQUEST_METHOD'] != 'POST' ||
empty($_SERVER['CONTENT_TYPE']) ||
$_SERVER['CONTENT_TYPE'] != 'application/json'
) {
return false;
}
$request = json_decode(file_get_contents('php://input'),true);
$args=func_get_args();
ob_start();
var_dump($_SERVER);
$result2 = ob_get_clean();
$file = 'stripedump.txt';
$current = file_get_contents($file);
$current .= $result2;
file_put_contents($file, $current);
try {
if ($result = @call_user_func_array(array($object,$request['method']),$request['params'])) {
$response = array (
'id' => $request['id'],
'result' => $result,
'error' => NULL
);
} else {
$response = array (
'id' => $request['id'],
'result' => NULL,
'error' => 'unknown method or incorrect parameters'
);
}
} catch (Exception $e) {
$response = array (
'id' => $request['id'],
'result' => NULL,
'error' => $e->getMessage()
);
}
if (!empty($request['id'])) { // notifications don't want response
header('content-type: text/javascript');
echo json_encode($response);
}
return true;
}
}
?>
<?php
require_once 'example.php';
require_once 'jsonRPCServer.php';
$myExample = new example();
jsonRPCServer::handle($myExample)
or print 'no request';
echo '<b>Attempt to perform basic operations</b><br />'."\n";
try {
echo 'Your name is <i>'.$myExample->giveMeSomeData('name').'</i><br />'."\n";
$myExample->changeYourState('I am using this funnction from the local environement');
echo 'Your status request has been accepted<br />'."\n";
} catch (Exception $e) {
echo nl2br($e->getMessage()).'<br />'."\n";
}
var_dump($myExample);
echo '<br /><b>Attempt to store strategic data</b><br />'."\n";
try {
$myExample->writeSomething('bite me');
echo 'Strategic data succefully stored';
} catch (Exception $e) {
echo nl2br($e->getMessage());
}
?>
tcpdump:
00:29:06.659025 IP 192.168.0.55.52841 > 108.61.175.20.vultr.com.http: Flags [P.], seq 1:148, ack 1, win 115, options [nop,nop,TS val 2017270703 ecr 2483478707], length 147
E....A@.@.f....7l=...i.P...g.I.]...s.......
x=......POST /hooker/ HTTP/1.1
Host: nyccomm.com
User-Agent: curl/7.42.1
Accept: */*
Content-Type: application/json
Content-Length: 9
{foo:bar}
00:29:06.746198 IP 108.61.175.20.vultr.com.http > 192.168.0.55.52841: Flags [P.], seq 1:561, ack 148, win 1033, options [nop,nop,TS val 2483478793 ecr 2017270703], length 560
E..dm.@.5...l=.....7.P.i.I.]....... :......
... x=..HTTP/1.1 200 OK
Date: Thu, 09 Jul 2015 08:03:21 GMT
Server: Apache/2.4.12 (FreeBSD) PHP/5.6.10
X-Powered-By: PHP/5.6.10
Content-Length: 373
Content-Type: text/html; charset=UTF-8
<b>Attempt to perform basic operations</b><br />
Your name is <i>Bubba</i><br />
Your status request has been accepted<br />
object(example)#1 (1) {
["someData":"example":private]=>
array(2) {
["name"]=>
string(5) "Bubba"
["attr"]=>
string(17) "Some me Attribute"
}
}
<br /><b>Attempt to store strategic data</b><br />
Strategic data succefully stored
00:29:06.746271 IP 192.168.0.55.52841 > 108.61.175.20.vultr.com.http: Flags [.], ack 561, win 123, options [nop,nop,TS val 2017270790 ecr 2483478793], length 0
E..4.B@.@.gP...7l=...i.P.....I.....{.W.....
00:29:06.659025 IP 192.168.0.55.52841>108.61.175.20.vultr.com.http:Flags[P.],seq 1:148,ack 1,win 115,选项[nop,nop,TS val 2017270703 ecr 2483478707],长度147
EA@.@.f.…7l=…i.P.…g.i.]…s。。。。。。。
x=…POST/hooker/HTTP/1.1
主持人:nycomm.com
用户代理:curl/7.42.1
接受:*/*
内容类型:application/json
内容长度:9
{foo:bar}
00:29:06.746198 IP 108.61.175.20.vultr.com.http>192.168.0.55.52841:旗帜[P],序号1:561,确认148,赢1033,选项[nop,nop,TS val 248347893 ecr 2017270703],长度560
E.dm.@.5…l=…7.P.i.i.]:。。。。。。
... x=…HTTP/1.1200正常
日期:2015年7月9日星期四08:03:21 GMT
服务器:Apache/2.4.12(FreeBSD)PHP/5.6.10
X-Powered-By:PHP/5.6.10
内容长度:373
内容类型:text/html;字符集=UTF-8
尝试执行基本操作
你的名字叫布巴
您的状态请求已被接受
对象(示例)#1(1){
[“someData”:“example”:private]=>
阵列(2){
[“名称”]=>
字符串(5)“Bubba”
[“attr”]=>
字符串(17)“某些me属性”
}
}
尝试存储战略数据
战略数据成功存储
00:29:06.746271 IP 192.168.0.55.52841>108.61.175.20.vultr.com.http:Flags[.],ack 561,win 123,选项[nop,nop,TS val 2017270790 ecr 2483478793],长度0
E..4。B@.@.gP…7l=…i.P…..i….{.W。。。。。
如何从入站RPC对象访问JSON数据?(特别是“foo:bar”)当全部由其自身使用时,此功能有效
<?php
$request = file_get_contents('php://input');
$args=func_get_args();
ob_start();
var_dump($request);
$result2 = ob_get_clean();
$file = 'stripedump.txt';
$current = file_get_contents($file);
$current .= $result2;
file_put_contents($file, $current);
?>
00:29:06.659025 IP 192.168.0.55.52841 > 108.61.175.20.vultr.com.http: Flags [P.], seq 1:148, ack 1, win 115, options [nop,nop,TS val 2017270703 ecr 2483478707], length 147
E....A@.@.f....7l=...i.P...g.I.]...s.......
x=......POST /hooker/ HTTP/1.1
Host: nyccomm.com
User-Agent: curl/7.42.1
Accept: */*
Content-Type: application/json
Content-Length: 9
{foo:bar}
00:29:06.746198 IP 108.61.175.20.vultr.com.http > 192.168.0.55.52841: Flags [P.], seq 1:561, ack 148, win 1033, options [nop,nop,TS val 2483478793 ecr 2017270703], length 560
E..dm.@.5...l=.....7.P.i.I.]....... :......
... x=..HTTP/1.1 200 OK
Date: Thu, 09 Jul 2015 08:03:21 GMT
Server: Apache/2.4.12 (FreeBSD) PHP/5.6.10
X-Powered-By: PHP/5.6.10
Content-Length: 373
Content-Type: text/html; charset=UTF-8
<b>Attempt to perform basic operations</b><br />
Your name is <i>Bubba</i><br />
Your status request has been accepted<br />
object(example)#1 (1) {
["someData":"example":private]=>
array(2) {
["name"]=>
string(5) "Bubba"
["attr"]=>
string(17) "Some me Attribute"
}
}
<br /><b>Attempt to store strategic data</b><br />
Strategic data succefully stored
00:29:06.746271 IP 192.168.0.55.52841 > 108.61.175.20.vultr.com.http: Flags [.], ack 561, win 123, options [nop,nop,TS val 2017270790 ecr 2483478793], length 0
E..4.B@.@.gP...7l=...i.P.....I.....{.W.....
<?php
$request = file_get_contents('php://input');
$args=func_get_args();
ob_start();
var_dump($request);
$result2 = ob_get_clean();
$file = 'stripedump.txt';
$current = file_get_contents($file);
$current .= $result2;
file_put_contents($file, $current);
?>