Server Reference Guide : JSON-RPC 2.0 Interface : Sending JSON-RPC Requests to the Server Application : Sending an HTTP POST Request Containing the JSON-RPC Request
 
Share this page          
Sending an HTTP POST Request Containing the JSON-RPC Request
A JSON-RPC request can be sent by an HTTP POST request to a URL that is served by the Java-based OpenROADJSONRPC servlet.
The data of the HTTP POST request must be a JSON-RPC 2.0-conforming request string.
Sending HTTP POST requests can be done programmatically (for example, by using language-specific classes for HTTP requests) or using command-line utilities such as curl.
Example 1: Using curl to send an HTTP POST request
Http://myserver:8080/openroad/jsonrpcservertest is the URL of the OpenROADJSONServer for the jsonrpcservertest application:
curl -d "{\"jsonrpc\": \"2.0\", \"id\": 2, \"method\": \"subtract\", \"params\": {\"subtrahend\": 23.4, \"minuend\": 42.8},}" --header "Content-Type: application/json" http://myserver:8080/openroad/jsonrpcservertest
This results in the following response string of the HTTP request:
{"result":19.400, "id":2, "jsonrpc":"2.0"}
Example 2: Using the ServerXMLHTTP COM object in VBA
Dim httpReq As Object
Dim jsonrpcReq As String
Dim strResponse As String
jsonrpcReq = "{""jsonrpc"": ""2.0"", ""id"": 1, ""method"": ""subtract"", " & _
  """params"": {""subtrahend"": 23.4, ""minuend"": 42.8}}"
Set httpReq = CreateObject("MSXML2.ServerXMLHTTP")
httpReq.Open "POST", "http://myserver:8080/openroad/jsonrpcservertest", False
httpReq.Send jsonrpcReq
strResponse = httpReq.responseText
'ToDo: Parse the JSON in strResponse and populate the result
MsgBox strResponse