سؤال

I've been trying to figure this out for 2 days. I've tried every JSONRPC library there is, but none of them worked so I resorted to doing it myself.

I make a simple AJAX call to the proxy - written in PHP - and POST the request JSON:

$.ajax({
  url: "includes/buoybay_proxy.php",
  dataType: "json",
  data: {"method": "Test", "params": ["113f8ba8*****************9b5f27e0a0bb"], "id": 1},
  timeout: 5000,
  type: 'POST',
  success: function(data, status, XHR){
      console.log("!!: " + JSON.stringify(data));
  },
  error: function(jqXHR, textStatus, errorThrown) {
    console.log("??: ", textStatus, errorThrown);
  }
});

The proxy - written in PHP - works as follows:

$con = json_encode($_POST);
$cparams = array(
    'http' => array(
        'content' => $con,
        'method' => 'POST',
        'ignore_errors' => true,
        'header' => 'POST /studs/**************/server.php HTTP/1.0\r\n
                    User-Agent: "User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1468.0 Safari/537.36\r\n"
                    Host: my.wamp.server:80\r\n
                    Accept-Charset: UTF-8,ISO-8859-1,US-ASCII\r\n
                    Content-Type: application/json\r\n
                    Content-Length: ' . strlen($con) . '\r\n'
    )
);
//ChromePhp::log($cparams);
$context = stream_context_create($cparams);
$fp = fopen('http://mw.buoybay.org:80/studs/**************/server.php', 'r', false, $context);
//ChromePhp::log(stream_get_contents(($fp)));
echo json_encode(stream_get_contents(($fp)));

This results in the following error message from the server:

{"id": null, "error": { "faultCode": 15, "faultString": "Invalid request payload Invalid data (empty string?)" }, "result": null}     

I'm simply out of ideas; can anyone fix this or at least point me in the right direction?

هل كانت مفيدة؟

المحلول

This is what ended up working (PHP not written by me); the AJAX was fine except I should have been using GET.

AJAX Proxy:

<?php
require_once('jsonRPCClient.php');
include('ChromePhp.php');
$url='http://mw.buoybay.org/studs/studs_cdrh/jsonrpc_cdrh/server.php';
$constellation="CBIBS";
$apikey="113f8ba8f286ad********************f27e0a0bb";
$client =new jsonRPCClient($url,true);

$method=$_GET['method'];//"RetrieveCurrentReadings";
$getParams =  $_GET['params'];
$params=explode(',', $getParams); //array('CBIBS','AN','113f8ba8f28******************279b5f27e0a0bb');
$result = $client->__call($method, $params);

// return the results
echo json_encode($result);
?>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top